views:

752

answers:

3

Does anyone know how to specify a bean as non lazy when using annotations to configure the bean?

+1  A: 

You cannot do that with annotation, only with XML. The question is, have you set the default to be lazy init:

<beans default-lazy-init="true">
    <!-- no beans will be pre-instantiated... -->
</beans>

The xml for setting a bean to be initialized on context initialization is

<bean id="lazy" class="com.foo.CheapToCreateBean" lazy-init="false"/>

and this is the default behavior.

David Rabinowitz
that is what I was worried about, I could not see the annotation for it... I wonder why they don't support it?
Michael Wiles
I don;t know either, but you can add a request here http://jira.springframework.org/browse/SPR
David Rabinowitz
+2  A: 

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

Priyank
A: 

In spring 3.0 there is an annotation: @Lazy(false)

Bozho