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;
    }
  • 相关阅读:
    美团容器平台架构及容器技术实践
    【人物志】美团首席科学家夏华夏:不断突破边界的程序人生
    Category 特性在 iOS 组件化中的应用与管控
    浅谈大型互联网企业入侵检测及防护策略
    【基本功】深入剖析Swift性能优化
    CAT 3.0 开源发布,支持多语言客户端及多项性能提升
    安装window下的redis,redis可视化管理工具(Redis Desktop Manager)安装,基础使用,实例化项目
    .Net Core Redis的使用
    焦点IT Redis安装与配置( Windows10 或Windows server)
    用VScode配置Python开发环境
  • 原文地址:https://www.cnblogs.com/mufeng07/p/12200282.html
Copyright © 2011-2022 走看看