当前位置:网站首页>@Difference between component and @configuration
@Difference between component and @configuration
2022-06-29 16:54:00 【Little code bear】
@Configuration In essence @Component, also @Configuration The marked class must meet the following requirements :
1. Configuration class cannot be final class 、 Must be declared as static
2. Configuration annotations are usually used to pass @Bean Annotation generation Spring Container managed classes , It is usually meant to indicate that this is a configuration class , Use this class to register multiple Bean
3. Configuration classes can be declared in methods , It can't be private
Important differences
If you use @Configuration Annotated class , And in this note proxyBeanMethods The value of the property is true, Will be for this bean Create a proxy class , This proxy class will intercept all the @Bean The method of decoration , In the method logic of interception , The required singleton object will be returned from the container .
Use @Component Annotated class , Not for this bean Create a proxy class . Then we will directly execute the user's method , So every time a new object is returned .
If we were to @Configuration In the annotations proxyBeanMethods Property is set to false, Then whether its behavior will follow @Component The annotation is the same ?
@Configuration(proxyBeanMethods = false)
public class Config {
@Bean
public Hello hello(){
return new Hello();
}
}

Pass the result , We can conclude that : If you will @Configuration In the annotations proxyBeanMethods Property is set to false, Then its behavior will follow @Component The annotation is the same . So the biggest difference is , One uses the singleton mode and the other does not
Reference boss :https://juejin.cn/post/6873314485449261069
边栏推荐
- C# Winfrom Chart图表控件 柱状图、折线图
- Problem solving metauniverse, multi communication scheme in online games
- In order to prevent being rectified after 00, a company requires employees not to sue the company
- Simulink simulation mode
- Inheritablethreadlocal resolves message loss during message transmission between parent and child threads in the thread pool
- 最高81.98%!超百所“双一流”高校本科深造率公布
- Which version of JVM is the fastest?
- 6.25atcoderabc257e - addition and multiplication 2
- 指南针开户炒股是否安全?个人怎样开户炒股
- Tool chain empowers hundreds of companies, horizon opens the "Matthew effect" of mass production of intelligent driving
猜你喜欢

Metadata management Apache Atlas Compilation integration deployment and testing

使用kalibr标定工具进行单目相机和双目相机的标定

元代理模型可迁移对抗攻击

八年测开经验面试28K公司后,吐血整理出高频面试题和答案

【 OpenGL 】 Random Talk 1. The camera rotates around a point in the space by dragging the mouse

curl: (56) Recv failure: Connection reset by peer

UWB precise positioning scheme, centimeter level high-precision technology application, intelligent pairing induction technology

图文带你彻底弄懂MySQL事务原子性之UndoLog

Picture and text show you how to thoroughly understand the atomicity of MySQL transaction undolog

Étalonnage de la caméra monoculaire et de la caméra binoculaire à l'aide de l'outil d'étalonnage kalibr
随机推荐
元代理模型可迁移对抗攻击
What are the Commonwealth countries
同样是做测试,为什么别人年薪30W+?
【 OpenGL 】 Random Talk 1. The camera rotates around a point in the space by dragging the mouse
Advanced webgl performance optimization
图文带你彻底弄懂MySQL事务原子性之UndoLog
After eight years of testing and opening experience and interview with 28K company, hematemesis sorted out high-frequency interview questions and answers
[proteus simulation] 8-bit nixie tube dynamic scanning display change data
6.25atcoderabc257e - addition and multiplication 2
MySQL foundation - transaction
After reading the complete code
Real test = "half product + Half development"?
Comprehensive analysis of Seata distributed transaction at and XA
Kotlin basic grammar
In order to prevent being rectified after 00, a company requires employees not to sue the company
c# 国内外ORM 框架 dapper efcore sqlsugar freesql hisql sqlserver数据常规插入测试性能对比
MySQL基础——事务
我,大厂测试员,降薪50%去国企,后悔了...
What are the financial products suitable for the poor in 2022?
机器学习7-支持向量机