使用基于注解的配置创建延迟初始化的 Spring bean [英] Creating lazily initialized Spring beans using annotation based configuration
本文介绍了使用基于注解的配置创建延迟初始化的 Spring bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Spring 的 @Component
注释来配置 Spring 3.0 应用程序中的许多 bean.我想知道是否可以懒惰地构建其中一些 bean - 特别是 prototype
bean?
I am using Spring's @Component
annotation to configure many of the beans in my Spring 3.0 application. I would like to know if it's possible to construct some of these beans lazily - especially the prototype
beans?
推荐答案
要声明延迟初始化的 bean,您可以使用 @Lazy
注释.
To declare lazy-initialized bean you can use @Lazy
annotation.
但是请注意,它对 prototype
bean 没有意义——它们不能急切地初始化,所以没有必要将它们标记为惰性.
Note, however, that it doesn't make sense for prototype
beans - they can't be eagerly initialized, so there is no need to mark them lazy.
这篇关于使用基于注解的配置创建延迟初始化的 Spring bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文