Creating lazily initialized Spring beans using annotation based configuration

annotations, dependency-injection, java, lazy-loading, spring

Solution

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.

Problem

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?

Original source