Whhen trying to test caching capabilities of Hibernate\'s (version 4) EHCache between transactions - it fails: Failed to retrieve PlatformTransactionManager for @Trans
@Transactional requires a bean with name transactionManager in your application context if not specified explictly. Specify the transaction manager you want to use with your test using the @Transaction annotation value attribute
For example if you want to use hibernateTransactionManager specify this as
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { ApplicationConfig.class, CachingConfig.class }, loader = AnnotationConfigContextLoader.class)
@PersistenceContext
@Transactional("hibernateTransactionManager")
public class EHCacheTest extends AbstractTransactionalJUnit4SpringContextTests {
}
Otherwise rename the transaction manager you want to use to have the default name transactionManager
@Bean
public PlatformTransactionManager transactionManager() { // TODO: Really need this?
final HibernateTransactionManager transactionManager = new HibernateTransactionManager();
transactionManager.setSessionFactory(sessionFactory().getObject());
return transactionManager;
}