loc-framework
loc-framework copied to clipboard
关于多数据源事务的问题
`@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class,DataSourceTransactionManagerAutoConfiguration.class }) @EnableTransactionManagement public class SampleMybatisApplication {
public static void main(String[] args) throws Exception {
SpringApplication app = new SpringApplication(
SampleMybatisApplication.class);
app.run(args);
}
@Autowired
private HotMapper hotMapper;
@Autowired
private SecondHotMapper secondHotMapper;
@Transactional("firstTransactionManager")
@RequestMapping(value = "/transactional1", method = RequestMethod.GET)
public String transactional1() {
hotMapper.deleteById(10);
return "";
}
@Transactional("secondTransactionManager")
@RequestMapping(value = "/transactional2", method = RequestMethod.GET)
public String transactional2() {
secondHotMapper.deleteById(10);
return "";
}
}`
我的HotMapper 和 SecondHotMapper 是对应两个数据源的mapper,如果想添加事务的时候就必须像上面代码一样指定Transactional的名字,请问大神有什么好的办法,不需要业务层去关心当前使用的哪个事务么?
如果不指定事务名称, 暂时则不能区分要对哪个数据源进行事务功能。 或者您有什么好的建议可以进行自动识别来选择要进行事务的数据源