当前位置:网站首页>@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
边栏推荐
- Which is better and safer, GF e-gold or Dongfang fortune
- 6.25atcoderabc257e - addition and multiplication 2
- UWB precise positioning scheme, centimeter level high-precision technology application, intelligent pairing induction technology
- 关于onReachButton 不触发可能原因
- Practice | solution for image upload, rotation and compression on mobile terminal
- isEmpty 和 isBlank 的用法区别,居然一半的人答不上来?
- 【南京大学】考研初试复试资料分享
- Locust performance pressure test tool
- 我的远程办公初体验 | 社区征文
- 基于opencv进行双目相机的标定
猜你喜欢

After eight years of testing and opening experience and interview with 28K company, hematemesis sorted out high-frequency interview questions and answers

MySQL foundation - multi table query

【OpenGL】杂谈一、通过鼠标拖拽实现相机绕空间中的某点进行球面旋转查看

Stable currency risk profile: are usdt and usdc safe?

Review of mathematical knowledge: curve integral of type I

能够1年涨薪2次的软件测试工程师,他到底强在哪里?

使用kalibr標定工具進行單目相機和雙目相機的標定

Fluent的msh格式网格学习

Which version of JVM is the fastest?
![[untitled]](/img/e2/be57a7e22275af59183c50e0710837.png)
[untitled]
随机推荐
c# 国内外ORM 框架 dapper efcore sqlsugar freesql hisql sqlserver数据常规插入测试性能对比
New feature of C11 - Auto and decltype type type indicators
[proteus simulation] 8-bit nixie tube dynamic scanning display change data
解题元宇宙,网络游戏中的多元通信方案
Calibration of binocular camera based on OpenCV
Tool chain empowers hundreds of companies, horizon opens the "Matthew effect" of mass production of intelligent driving
能够1年涨薪2次的软件测试工程师,他到底强在哪里?
Metadata management Apache Atlas Compilation integration deployment and testing
6.26CF模拟赛D:黑白条题题解
Simulink simulation mode
最高81.98%!超百所“双一流”高校本科深造率公布
函数计算异步任务能力介绍 - 任务触发去重
isEmpty 和 isBlank 的用法区别,居然一半的人答不上来?
STM32 key chattering elimination -- Thinking of entry state machine
flink sql rownumber 报错。谁遇到过啊?怎么解决?
Étalonnage de la caméra monoculaire et de la caméra binoculaire à l'aide de l'outil d'étalonnage kalibr
如何配置 logback?30分钟让你彻底学会代码熬夜敲
C语言微博用户管理系统
Apache atlas breakpoint view
Mathematical knowledge: finding combinatorial number II - finding combinatorial number