Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to specify a bean as non lazy with annotations

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

like image 889
Michael Wiles Avatar asked Jun 22 '09 13:06

Michael Wiles


People also ask

How do you annotate a bean?

One of the most important annotations in spring is the @Bean annotation which is applied on a method to specify that it returns a bean to be managed by Spring context. Spring Bean annotation is usually declared in Configuration classes methods. This annotation is also a part of the spring core framework.

What is @lazy annotation in Spring?

@Lazy annotation indicates whether a bean is to be lazily initialized. It can be used on @Component and @Bean definitions. A @Lazy bean is not initialized until referenced by another bean or explicitly retrieved from BeanFactory . Beans that are not annotated with @Lazy are initialized eagerly.

Is @bean method level annotation?

@Bean is a method-level annotation and a direct analog of the XML <bean/> element. The annotation supports most of the attributes offered by <bean/> , such as: init-method , destroy-method , autowiring , lazy-init , dependency-check , depends-on and scope .

What is @scope annotation in Spring?

When used as a type-level annotation in conjunction with @Component , @Scope indicates the name of a scope to use for instances of the annotated type. When used as a method-level annotation in conjunction with @Bean , @Scope indicates the name of a scope to use for the instance returned from the method.


1 Answers

In spring 3.0 there is an annotation: @Lazy(false). But note that beans are eager by default.

like image 107
Bozho Avatar answered Sep 23 '22 04:09

Bozho