I am attempting to build a brand new Spring Framework 4.0 project without all of the magical gradle stuff, but simply kicking it old school.
I am following the tutor
though this article is pretty old and has already bean answered, i encountered the same problem with the oficial turorial spring-data-jpa on spring-io website.
the current spring data jpa example/spring io guide detects at least 2 beans implementing the interface "EntityManager". You must help spring what implementation to wire to. I recommend to add a qualifier.
In class JPAConfiguration add:
@Bean
@Qualifier(value = "entityManager")
public EntityManager entityManager(EntityManagerFactory entityManagerFactory) {
return entityManagerFactory.createEntityManager();
}
In the test class add:
@Autowired
@Qualifier(value = "entityManager")
EntityManager manager;
Hope it helps you.
I would not necessarily use the "PersistenceContext", as spring handles the creation of transaction manager, entitymanager, beans, datasource etc.. "PersisenceConetext" annotation is basically defined for container managed entityfactory of an application server/ejb compliant container