Closed
Description
Michael Isvy opened SPR-6474 and commented
Please consider that you need to declare an EntityManagerFactory using JavaConfig.
Currently, the code you need to write looks like this:
@Bean
public EntityManagerFactory entityManagerFactory() {
LocalContainerEntityManagerFactoryBean entityManagerFactory = new
LocalContainerEntityManagerFactoryBean();
//...
entityManagerFactory.afterPropertiesSet();
return entityManagerFactory.getObject();
}
There are 2 things that I can easily forget here: the calls to afterPropertiesSet() and to getObject(). It will be much easier if we provide a convenience class called ConfigurationUtils that we could use in that way:
@Bean
public EntityManagerFactory entityManagerFactory() {
LocalContainerEntityManagerFactoryBean entityManagerFactory = new
LocalContainerEntityManagerFactoryBean();
//...
return ConfigurationUtils.proceedFactoryBean(entityManagerFactory);
}
Issue Links:
- Provide alternatives to using FactoryBean types within @Bean methods [SPR-7418] #12076 Provide alternatives to using FactoryBean types within
@Bean
methods ("is superseded by")