I have simple Spring 4 WebMVC app (Java-config), and I want to add JPA. But when I try to run app (as deloyed on Tomcat) I get: What can be a source of error?
in this question I posted a full example how to unit test a spring controller which needs an autowired JpaRepository.
You're missing completly DB configuration in your Config
class.
Try this for example:
@Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("org.hsqldb.jdbc.JDBCDriver");
dataSource.setUrl("jdbc:hsqldb:mem:testdb");
dataSource.setUsername("sa");
dataSource.setPassword("");
return dataSource;
}
@Bean
public EntityManager entityManager() {
return entityManagerFactory().getObject().createEntityManager();
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan("package.where.your.entites.like.CustSys.are.stored");
return em;
}