创建使用基于注解配置的延迟初始化的Spring bean [英] Creating lazily initialized Spring beans using annotation based configuration

查看:193
本文介绍了创建使用基于注解配置的延迟初始化的Spring bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Spring的 @Component 注释配置许多豆子在我的Spring 3.0的应用程序。我想知道,如果它可以构建一些豆类懒洋洋地 - 尤其是原型豆类


解决方案

要申报延迟初始化的bean可以使用<一个href=\"http://static.springsource.org/spring/docs/3.0.x/api/org/springframework/context/annotation/Lazy.html\"><$c$c>@Lazy注释。

但是请注意,这是没有道理的原型豆类 - 他们不能被急切地初始化,因此没有必要将它们标记懒<。 / p>

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?

解决方案

To declare lazy-initialized bean you can use @Lazy annotation.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆