Spring Boot @Configuration 和 @Component
来源:互联网 发布:平面广告图制作软件 编辑:程序博客网 时间:2024/06/07 23:40
转载自:http://blog.csdn.net/isea533/article/details/78072133
@Configuration中所有带@Bean注解的方法都会被动态代理,调用该方法返回的都是同一个实例。
@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)@Documented@Componentpublic @interface Configuration { String value() default "";}
从定义来看,@Configuration注解本质上还是@Component,因此<context:component-scan/>
或者@ComponentScan
都能处理@Configuration注解的类。
@Configuration 标记的类必须符合下面的要求:
- 配置类必须以类的形式提供(不能是工厂方法返回的实例),允许通过生成子类在运行时增强(cglib 动态代理)。
- 配置类不能是 final 类(没法动态代理)。
- 配置注解通常为了通过 @Bean 注解生成 Spring 容器管理的类。
- 配置类必须是非本地的(即不能在方法中声明,不能是 private)。
- 任何嵌套配置类都必须声明为static。
- @Bean方法不能创建进一步的配置类(也就是返回的bean如果带有@Configuration,也不会被特殊处理,只会作为普通的 bean)。
Spring 容器在启动时,会加载默认的一些PostPRocessor,其中就有 ConfigurationClassPostProcessor
,这个后置处理程序专门处理带有@Configuration注解的类,这个程序会在bean定义加载完成后,在bean初始化前进行处理。主要处理的过程就是使用 cglib 动态代理增强类,而且是对其中带有@Bean注解的方法进行处理。
但是对于@Component,@Component 注解并没有通过cglib来代理@Bean方法的调用,因此调用带@Bean注解的方法态返回的都是新的实例。
阅读全文
0 0
- Spring Boot @Configuration 和 @Component
- Spring @Configuration 和 @Component 区别
- Spring Boot Externalized Configuration
- spring-boot配置(一):@Configuration,@ConfigurationProperties和application.yml
- spring的注解(1): @Configuration,@Bean,@Component,
- 学习Spring boot 注解 @Value @Component @ConfigurationProperties
- Spring Boot自动配置(Auto-Configuration),@EnableAutoConfiguration,Spring Beans和依赖注入
- spring boot--creating your own auto-configuration
- 理解Spring Boot中的auto-configuration
- spring @Configuration 和 @Bean
- Spring Java Configuration之@Configuration和@Bean
- Spring 的@Component和@Autowired
- Spring-boot项目additional-spring-configuration-metadata.json源码
- @Bean在@Configuration和在@Component中的区别
- Spring注解:@Configuration和@Bean
- [Exception]spring-boot Failed to start component [StandardServer[-1]]
- spring boot conditionBean MissingBean @configuration 配置不存在问题
- Load multiple configuration files from different directories with Spring Boot
- easydss与linux内核接收网络数据流程(四)
- 第6章任务3:创建登录界面
- 367. Valid Perfect Square
- 赋值中的类型转换
- Oc 滚动视图
- Spring Boot @Configuration 和 @Component
- (六)生成器
- 学生的成绩
- CodeForces
- NOIP2016普及组复赛买铅笔
- 24点
- [BZOJ]1426 收集邮票 概率与期望
- Oc LocateMap(地图定位)
- codeforces 864B