0

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.

Cosmin D
  • 639
  • 1
  • 11
  • 24

2 Answers2

4

In your spring data configs you should add a parameter to

@EnableJpaRepositories(transactionManagerRef = "jtaTransactionManager")

the default value is "transactionManager"

Yuri Plevako
  • 311
  • 1
  • 6
0

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

Community
  • 1
  • 1
mexes_s
  • 449
  • 3
  • 9
  • Sorry. It is a bean. I just skipped it by mistake. I updated the post. – Cosmin D Sep 16 '16 at 10:26
  • I have added @Transactional(transactionManager="jpaTransactionManager") also on repository, but same result. Anyway, I don't want repository methods to be transactional. Just to wrap the service method in transaction. – Cosmin D Sep 16 '16 at 10:29