Spring5.2 @Configuration 属性 proxyBeanMethods 作用
所属分类 springboot
浏览量 1129
如果@Bean 方法之间没有调用关系 ,可以把 proxyBeanMethods 设置为 false
否则,方法内部引用的 和 Spring 容器中的 是两个不同的实例
org.springframework.context.annotation.Configuration
boolean proxyBeanMethods() default true;
proxyBeanMethods 设置 为 false , 变成 lite bean 模式
配置类不在生成CGLIB子类,提高运行性能,降低启动时间
@Bean方法 可以是 private final
不能在 @Bean方法内调用其他的 @Bean方法 (bean之间的依赖 ,可以放在bean方法参数里)
Specify whether @Bean methods should get proxied in order to enforce bean lifecycle behavior,
e.g. to return shared singleton bean instances even in case of direct @Bean method calls in user code.
@Bean 方法代理,保证bean 生命周期,譬如 @Bean 方法内部调用 保证获取到共享的单例对象
This feature requires method interception, implemented through a runtime-generated CGLIB subclass
which comes with limitations such as the configuration class and its methods not being allowed to declare final.
运行时生成CGLIB子类 ,方法不能为 final
The default is true, allowing for 'inter-bean references' via direct method calls
within the configuration class as well as for external calls to this configuration's @Bean methods,
e.g. from another configuration class.
If this is not needed since each of this particular configuration's @Bean methods is self-contained
and designed as a plain factory method for container use,
switch this flag to false in order to avoid CGLIB subclass processing.
设置成 false ,避免 生成 CGLIB 子类
Turning off bean method interception effectively processes @Bean methods individually
like when declared on non- @Configuration classes, a.k.a. @Bean Lite Mode .
It is therefore behaviorally equivalent to removing the @Configuration stereotype.
@since 5.2
上一篇
下一篇
TBA聊考研
springboot REST api 实例
基于 HttpURLConnection 的 http 客户端
aerospike 乐观锁实例
Maven设置项目编码及jdk版本
springboot配置大全