如何使用注释将 bean 指定为非惰性 bean
有谁知道在使用注释配置 bean 时如何将 bean 指定为非惰性 bean?
Does anyone know how to specify a bean as non lazy when using annotations to configure the bean?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 spring 3.0 中有一个注释:
@Lazy(false)
。 但请注意,bean 默认情况下是 eager。In spring 3.0 there is an annotation:
@Lazy(false)
. But note that beans are eager by default.默认情况下,Bean 不是惰性的。 然而,就注释而言,目前注释似乎不支持它。
http://forum.springsource.org/showthread.php?t=62931
Spring 的下一个版本似乎已经有了一些东西
http://jira.springframework.org/browse/SJC-263
Beans are not lazy by default. However as far as annotations are concerned it seems like currently annotations do not support it.
http://forum.springsource.org/showthread.php?t=62931
Spring's next version though seem to have something in store
http://jira.springframework.org/browse/SJC-263
为了把事情搞清楚,要知道对于 Spring 3.0 及更高版本,bean 默认情况下是急切初始化的。
摘自
@Lazy(false )
Bozho 答案中的链接:Just to set things straight, be known that as to Spring 3.0 and later, beans are by default eagerly initialized.
Excerpt from the
@Lazy(false)
link in Bozho's answer:我在配置注释类中尝试了@EnableScheduling,结果成功了。
I tried @EnableScheduling in my Configuration Annotation class and that did the trick.