zoukankan      html  css  js  c++  java
  • SpringBoot的@Import和@ImportResource

    1. @Import
      • 源码  
    @Target(ElementType.TYPE)
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    public @interface Import {
    
        /**
         * {@link Configuration @Configuration}, {@link ImportSelector},
         * {@link ImportBeanDefinitionRegistrar}, or regular component classes to import.
         */
        Class<?>[] value();
    
    }
      • 使用说明  
      1. 导入@Configuration注解的配置类(4.2版本之前只可以导入配置类,4.2版本之后也可以导入普通类)
      2. 导入ImportSelector的实现类
      3. 导入ImportBeanDefinitionRegistrar的实现类
    1. @ImportResource
      • 源码
        @Retention(RetentionPolicy.RUNTIME)
        @Target(ElementType.TYPE)
        @Documented
        public @interface ImportResource {
        
            /**
             * Alias for {@link #locations}.
             * @see #locations
             * @see #reader
             */
            @AliasFor("locations")
            String[] value() default {};
        
            /**
             * Resource locations from which to import.
             * <p>Supports resource-loading prefixes such as {@code classpath:},
             * {@code file:}, etc.
             * <p>Consult the Javadoc for {@link #reader} for details on how resources
             * will be processed.
             * @since 4.2
             * @see #value
             * @see #reader
             */
            @AliasFor("value")
            String[] locations() default {};
        
            /**
             * {@link BeanDefinitionReader} implementation to use when processing
             * resources specified via the {@link #value} attribute.
             * <p>By default, the reader will be adapted to the resource path specified:
             * {@code ".groovy"} files will be processed with a
             * {@link org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader GroovyBeanDefinitionReader};
             * whereas, all other resources will be processed with an
             * {@link org.springframework.beans.factory.xml.XmlBeanDefinitionReader XmlBeanDefinitionReader}.
             * @see #value
             */
            Class<? extends BeanDefinitionReader> reader() default BeanDefinitionReader.class;
        
        }
      • 使用说明

           @ImportResource等同于xml配置:<import resource="配置文件.xml" />

  • 相关阅读:
    使用 JDBC 驱动程序
    (转载)SQL Server 2008 连接JDBC详细图文教程
    (转载)VB中ByVal与ByRef的区别
    (转载)Java里新建数组及ArrayList java不允许泛型数组
    在VS2008环境下编写C语言DLL,并在C++和C#项目下调用 (转载)
    近期计划
    在服务器上使用python-gym出现的关于显示的问题
    字符串匹配
    Ubuntu18.04 桌面系统的个人吐槽(主要是终端)
    Ubuntu18.04上安装N卡驱动、CUDA、CUDNN三连
  • 原文地址:https://www.cnblogs.com/dai-tao/p/13125316.html
Copyright © 2011-2022 走看看