Creating lazily initialized Spring beans using ann

2019-02-14 08:39发布

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?

2条回答
做个烂人
2楼-- · 2019-02-14 08:57

Lazy initialization isn't an option in the context of prototype-scoped beans. Those beans are instantiated and initialized on demand every time something asks for them, so they are, by nature, lazily initialized.

查看更多
Deceive 欺骗
3楼-- · 2019-02-14 09:09

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.

查看更多
登录 后发表回答