wichtounet
Apr 21st, 2009, 07:14 AM
Hi,
I'm converting my spring configuration to use JavaConfig and i've a problem with component-scan.
Before using JavaConfig, i used a ClassPathBeanDefinitionScanner. I need lazy-init on the beans, so i made :
BeanDefinitionDefaults defaults = new BeanDefinitionDefaults();
defaults.setLazyInit(true);
scanner.setBeanDefinitionDefaults(defaults);
But now, i didn't found how to do that in JavaConfig. I thougt that i can just set the defaultLazy option of the @Configuration, but it didn't work.
Actually, i use the context like that :
JavaConfigApplicationContext configApplicationContext =
new JavaConfigApplicationContext(SpringConfiguration.c lass, FilmsSpringConfiguration.class, PrimaryConfiguration.class);
And my three configurations looks like that :
@ComponentScan("org.jtheque.core.managers.persistence.context")
@Configuration(defaultLazy = Lazy.TRUE)
@AnnotationDrivenConfig
@AnnotationDrivenTx(transactionManager = "txManager")
public class SpringConfiguration extends ConfigurationSupport{
@Bean
public EntityManagerFactory entityManagerFactory(){
EntityManagerFactoryBean factory = new EntityManagerFactoryBean();
return (EntityManagerFactory)getObject(factory);
}
@Bean
public JpaTransactionManager txManager(){
return new JpaTransactionManager(entityManagerFactory());
}
@Bean
public ResourceBundleMessageSource messageSource(){
return new ResourceBundleMessageSource();
}
}
@Configuration(defaultLazy = Lazy.TRUE)
@ComponentScan(value = {
"org.jtheque.films.services.impl",
"org.jtheque.films.persistence.dao.impl",
"org.jtheque.films.view.impl.frames",
"org.jtheque.films.view.impl.panels",
"org.jtheque.films.controllers.impl"}
)
public class FilmsSpringConfiguration {
}
@Configuration(defaultLazy = Lazy.TRUE)
@ComponentScan(value = {
"org.jtheque.primary.dao.impl",
"org.jtheque.primary.services.impl",
"org.jtheque.primary.view.frames",
"org.jtheque.primary.controller"}
)
public class PrimarySpringConfiguration {
}
Is there a way to enable the lazy-initialization on my scanned components ?
Thank you very much and thanks for this very good project :)
I'm converting my spring configuration to use JavaConfig and i've a problem with component-scan.
Before using JavaConfig, i used a ClassPathBeanDefinitionScanner. I need lazy-init on the beans, so i made :
BeanDefinitionDefaults defaults = new BeanDefinitionDefaults();
defaults.setLazyInit(true);
scanner.setBeanDefinitionDefaults(defaults);
But now, i didn't found how to do that in JavaConfig. I thougt that i can just set the defaultLazy option of the @Configuration, but it didn't work.
Actually, i use the context like that :
JavaConfigApplicationContext configApplicationContext =
new JavaConfigApplicationContext(SpringConfiguration.c lass, FilmsSpringConfiguration.class, PrimaryConfiguration.class);
And my three configurations looks like that :
@ComponentScan("org.jtheque.core.managers.persistence.context")
@Configuration(defaultLazy = Lazy.TRUE)
@AnnotationDrivenConfig
@AnnotationDrivenTx(transactionManager = "txManager")
public class SpringConfiguration extends ConfigurationSupport{
@Bean
public EntityManagerFactory entityManagerFactory(){
EntityManagerFactoryBean factory = new EntityManagerFactoryBean();
return (EntityManagerFactory)getObject(factory);
}
@Bean
public JpaTransactionManager txManager(){
return new JpaTransactionManager(entityManagerFactory());
}
@Bean
public ResourceBundleMessageSource messageSource(){
return new ResourceBundleMessageSource();
}
}
@Configuration(defaultLazy = Lazy.TRUE)
@ComponentScan(value = {
"org.jtheque.films.services.impl",
"org.jtheque.films.persistence.dao.impl",
"org.jtheque.films.view.impl.frames",
"org.jtheque.films.view.impl.panels",
"org.jtheque.films.controllers.impl"}
)
public class FilmsSpringConfiguration {
}
@Configuration(defaultLazy = Lazy.TRUE)
@ComponentScan(value = {
"org.jtheque.primary.dao.impl",
"org.jtheque.primary.services.impl",
"org.jtheque.primary.view.frames",
"org.jtheque.primary.controller"}
)
public class PrimarySpringConfiguration {
}
Is there a way to enable the lazy-initialization on my scanned components ?
Thank you very much and thanks for this very good project :)