Spring Setup using @Configuration
Good Day,
I have been reading and trying out the samples provided in the http://blog.springsource.org but I'm block by an error that I'm not familiar with.
Quote:
[main] ERROR o.s.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'dataSource' defined in class path resource [org/config/DataConfig$Embedded.class]: No matching factory method found: factory bean 'dataConfig.Embedded'; factory method 'dataSource()'. Check that a method with the specified name exists and that it is non-static.
Given the following code:
Code:
@Configuration
public class DataConfig {
@Inject
private DataSource dataSource;
@Inject
private EntityManagerFactory entityManagerFactory;
@Bean
public EntityManagerFactory entityManagerFactory() {
LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();
entityManagerFactory.setDataSource(dataSource);
entityManagerFactory.setPersistenceProvider(new HibernatePersistence());
return entityManagerFactory.getObject();
}
@Bean
public PlatformTransactionManager transactionManager() {
JpaTransactionManager transactionManager = new JpaTransactionManager(entityManagerFactory);
transactionManager.setDataSource(dataSource);
transactionManager.setJpaDialect(new HibernateJpaDialect());
return transactionManager;
}
@Configuration
@Profile("embedded")
static class Embedded {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().setType(H2).build();
}
}
}
Here is a snippet of the web.xml
Code:
<context-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>org.config</param-value>
</context-param>
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>embedded</param-value>
</context-param>