Reputation: 739
I get following error when trying to use Spring transactions:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'transactionManager' is defined: No matching PlatformTransactionManager bean found for qualifier 'transactionManager' - neither qualifier match nor bean name match!
Although I have specified another name. Here is code snippet:
@EnableTransactionManagement
public class TransactionConfig {
...
@Bean
@Qualifier(value ="jpaTransactionManager")
public PlatformTransactionManager jpaTransactionManager(EntityManagerFactory emf) {
JpaTransactionManager tm = new JpaTransactionManager();
tm.setEntityManagerFactory(emf);
tm.setDataSource(primaryDataSource());
return tm;
}
@Bean()
@Qualifier(value="jtaTransactionManager")
public JtaTransactionManager jtaTransactionManager(UserTransactionManager atomikosTransactionManager) {
......
And I use it like this:
@Transactional(transactionManager="jpaTransactionManager")
public class UserService {
public Iterable<FVUser> findWithQuery(Specification<FVUser> spec) {
return repository.findAll(spec);
}
Repository :
@Repository
public interface UserRepository extends PagingAndSortingRepository<FVUser, String>, JpaSpecificationExecutor<FVUser> {
When debugging I noticed that it correctly uses "jpaTransactionManger" to call service method, but seems to look for a "transactionManager" to call the repository method, although no transaction is specified for it.
Anyone know why Spring is looking for default "transactionManager" bean in this case?
Thanks.
Upvotes: 0
Views: 4254
Reputation: 321
In your spring data configs you should add a parameter to
@EnableJpaRepositories(transactionManagerRef = "jtaTransactionManager")
the default value is "transactionManager"
Upvotes: 4
Reputation: 459
I think you should mark your PlatformTransactionManager
with @Bean
too.
And add @Transactional(transactionManager="jpaTransactionManager")
on your repository. Implementation uses by default @Transactional without parameterers, so that's why it is searching for default "transactionManager". It was explained there
Upvotes: 0