Spring @Configuration如何缓存对bean的引用

Spring @Configuration如何缓存对bean的引用,第1张

Spring @Configuration如何缓存对bean的引用

假设您创建的上下文有点像

AnnotationConfigApplicationContext context =    new AnnotationConfigApplicationContext(AppConfig.class);

由于

@Configuration
,Spring将创建一个类型的bean
AppConfig
并对其进行代理,因为它具有
@Bean
方法。你应该检查出
ConfigurationClassEnhancer
的实施细则。

这些方法不会直接在对象上调用。显然,它们不能,因为在编译时不知道它们。通过在代理服务器上进行反射来调用它们。

所以当你有

@Beanpublic CustomBean foo() {    return new CustomBean(bar());}

相当于

@Beanpublic CustomBean foo() {    return new CustomBean(this.bar());}

this
指的是其高速缓存方法调用,并立即如果它之前被调用它返回它的结果的代理。



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5507118.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-13
下一篇 2022-12-13

发表评论

登录后才能评论

评论列表(0条)

保存