No bean named 'transactionManager' is defined

前端 未结 4 1867
囚心锁ツ
囚心锁ツ 2020-12-06 04:51

I have configured two persistent units with the entity managers set up as show below:



        
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 05:19

    In your @Configuration file, if this is your dataSource:

    @Bean(name = "dataSource")
    public DataSource getDataSource() {
        return DataSourceBuilder
                .create()
                .username(username)
                .password(password)
                .url(url)
                .build();
    }
    

    this would be your transaction manager bean:

    @Bean(name = "DataSourceTransactionManager")
    public DataSourceTransactionManager getDataSourceTransactionManager() {
        return new DataSourceTransactionManager(getDataSource());
    }
    

    Then annotate the service method you would like to be transactional:

    @Transactional(transactionManager = "DataSourceTransactionManager", timeout = 60, rollbackFor = { Exception.class})
    

提交回复
热议问题