The old docs for Spring Javaconfig say that I can use
@Bean(scope=DefaultScopes.PROTOTYPE)
to get a prototype bean, but Spring 3.0.5's @Bean
doesn't seem to have this property.
Is there any way to control the scope of a bean in Javaconfig?
Use @Scope
instead.
Also, DefaultScopes
is not available in Spring core, but you can use BeanDefinition.SCOPE_PROTOTYPE
and BeanDefinition.SCOPE_SINGLETON
for convenience.
You can add @Scope("prototype")
for example:
@Bean
@Scope("prototype")
public DemoDao getDao() {
DemoDao dao = new DemoDao();
dao.setAddress("annoted:address");
dao.setName("annoted:name");
return dao;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With