当前位置:网站首页>@Detailed introduction of configuration annotation
@Detailed introduction of configuration annotation
2022-07-07 23:44:00 【TPH-BETTER】
from https://www.cnblogs.com/init-qiancheng/p/14623522.html
@Target({
ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Configuration {
@AliasFor(
annotation = Component.class
)
String value() default "";
boolean proxyBeanMethods() default true;
}
According to the definition of this annotation , The annotation is first a component , So it will be @SpringBootApplication Annotation scan ( The premise of scanning is that the annotation must be in the same package or sub package as the startup class ) There is an attribute in this annotation proxyBeanMethods, The default value for this property is true, This attribute can be divided into two modes
- Full Pattern ( Is the default ):proxyBeanMethods = true;
- Lite Pattern :proxyBeanMethods = false;
Full Patterns and Lite The difference between patterns
Use Full Pattern , This configuration class is represented , You can solve the dependencies between components , He will first check whether there are instances of components in the container , If it exists, it will be used directly , If it doesn't exist, it will be created ;
If it is Lite Pattern , There will be no proxy class , Each call will be executed once ,SpringBoot Will skip the steps of searching in the container ;
When to use Full and Lite
When there is no component dependency, it is used Lite, This will make the program start faster ;
When there is component dependency, it is used Full, Is the default ;
MyConfig.java
/** * 1、 The configuration class uses @Bean Label the method to register the component to the container , The default is also single instance * 2、 The configuration class itself is also a component * 3、proxyBeanMethods: agent bean Methods * Full(proxyBeanMethods = true)、【 Make sure that each @Bean Method is called many times and the returned component is single instance 】 * Lite(proxyBeanMethods = false)【 Every @Bean Method is called many times and the returned component is newly created 】 * Component dependencies must use Full Mode default . Other defaults are Lite Pattern */
@Configuration(proxyBeanMethods = false)// tell SpringBoot This is a configuration class == The configuration file
public class MyConfig {
/** * Full: No matter how many times you call the component registration method in the configuration class, you get the single instance object in the previous registration container * * @return */
@Bean// Add components to the container . Using the method name as the name of the component id. The return type is the component type . The value returned , Is an instance of a component in a container
public People people() {
return new People(1, " Transference ", dog());
}
@Bean
public Dog dog() {
return new Dog(1, " Hee hee ");
}
}
Start class
@SpringBootApplication
public class QianchengApplication {
public static void main(String[] args) {
ApplicationContext context = SpringApplication.run(QianchengApplication.class, args);
/** * Use Full Mode will output * [email protected]7aae97b * true */
/** * Use Late Mode output * [email protected] * false */
MyConfig bean = context.getBean(MyConfig.class);
System.out.println(bean);
People people = context.getBean("people", People.class);
Dog dog1 = context.getBean("dog", Dog.class);
System.out.println(people.getDog() == dog1);
}
}
边栏推荐
- 解析token的网址
- ASP. Net core middleware request processing pipeline
- Display the server hard disk image to the browser through Servlet
- Apng2gif solutions to various problems
- Flash encryption process and implementation of esp32
- Understand TCP's three handshakes and four waves with love
- 2022.7.7-----leetcode.648
- [stm32+esp8266 connect Tencent cloud IOT development platform 2] stm32+esp8266-01s connect Tencent cloud
- SAP HR 社会工作经历 0023
- Extended tree (I) - graphic analysis and C language implementation
猜你喜欢

archery安装测试

HB 5469 combustion test method for non-metallic materials in civil aircraft cabin

SAP 内存参数调优过程

SAP HR reward and punishment information export
![[stm32+esp8266 connects to Tencent cloud IOT development platform 3] stm32+esp8266-01s dynamically registers devices on Tencent cloud (at instruction mode) -- with source code](/img/55/ab50ead2564498cb214d98ac5b9c3d.jpg)
[stm32+esp8266 connects to Tencent cloud IOT development platform 3] stm32+esp8266-01s dynamically registers devices on Tencent cloud (at instruction mode) -- with source code

c—线性表

Flash encryption process and implementation of esp32
postgis学习

Dataguard 主备清理归档设置

0-1 knapsack problem
随机推荐
[stm32+esp8266 connect Tencent cloud IOT development platform 2] stm32+esp8266-01s connect Tencent cloud
通达信买基金安全吗?
Where are you going
Map operation execution process
Aitm3.0005 smoke toxicity test
SAP HR 家庭成员信息
解析token的网址
How to login and enable synchronization function in Google browser
平衡二叉樹【AVL樹】——插入、删除
HB 5469 combustion test method for non-metallic materials in civil aircraft cabin
Interface
FFA与ICGA造影
One of the anti climbing methods
SAP HR 社会工作经历 0023
【7.5】15. Sum of three numbers
平衡二叉树【AVL树】——插入、删除
Pycharm basic settings latest version 2022
P5594 [xr-4] simulation match
May day d-light
激光slam学习(2D/3D、偏实践)