zoukankan      html  css  js  c++  java
  • spring-context中@ImportSource的源码解析说明

    spring版本为5.0.11

    指示包含要导入的bean定义的一个或多个资源。它的功能比较像@Import注解,就是向容器内导入Bean。只是@ImportResource它导入的是一个xml配置文件,然后通过解析xml文件的方式再把解析好的Bean信息导入到Spring容器内。(主要用来过渡spring3,加载dubbo也是不错的)

    /**
     * Indicates one or more resources containing bean definitions to import.
     *
     * <p>Like {@link Import @Import}, this annotation provides functionality similar to
     * the {@code <import/>} element in Spring XML. It is typically used when designing
     * {@link Configuration @Configuration} classes to be bootstrapped by an
     * {@link AnnotationConfigApplicationContext}, but where some XML functionality such
     * as namespaces is still necessary.
     *
     * <p>By default, arguments to the {@link #value} attribute will be processed using a
     * {@link org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader GroovyBeanDefinitionReader}
     * if ending in {@code ".groovy"}; otherwise, an
     * {@link org.springframework.beans.factory.xml.XmlBeanDefinitionReader XmlBeanDefinitionReader}
     * will be used to parse Spring {@code <beans/>} XML files. Optionally, the {@link #reader}
     * attribute may be declared, allowing the user to choose a custom {@link BeanDefinitionReader}
     * implementation.
     *
     * @author Chris Beams
     * @author Juergen Hoeller
     * @author Sam Brannen
     * @since 3.0
     * @see Configuration
     * @see Import
     */
    @Retention(RetentionPolicy.RUNTIME)
    @Target({ElementType.TYPE})//只能标注在类上
    @Documented
    public @interface ImportResource {
        @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;
    }
  • 相关阅读:
    Python流程控制
    Python中的条件判断
    控制台出现“The script has an unsupported MIME type ('text/html')”报错
    React项目中使用hot-react-loader
    React组件绑定this的三种方法
    egg.js异步请求数据
    Zepto源码分析之二(新旧版本zepto.Z方法的区别)
    Zepto源码分析之一(代码结构及初始化)
    构建RN或Weex项目时,使用Android Studio常遇到的问题
    CentOS安装PHP7.*
  • 原文地址:https://www.cnblogs.com/mufeng07/p/12200282.html
Copyright © 2011-2022 走看看