update不会事务回滚求问大佬们是哪的问题?

# 用spring boot做数据导出时,插入数据抛异常可以事务回滚,但是update却不会事务回滚求问大佬们是哪的问题?

启动类


@SpringBootApplication(scanBasePackages = {"com.moredata"})


@MapperScan({"com.moredata.dao","com.moredata.dao.master"})

@ComponentScan(basePackages = "com.moredata.*")

@EnableTransactionManagement

@EnableAspectJAutoProxy

@EnableScheduling

public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @Bean
    public PlatformTransactionManager txManager(DataSource dataSource){
        return new DataSourceTransactionManager(dataSource);
    }

    @Bean
    public Object testBean(PlatformTransactionManager platformTransactionManager){
        System.out.println(">>>>>>>>>>"+platformTransactionManager.getClass().getName());
        return new Object();
    }
}

mapper不会回滚方法



public interface EmGrZsmxSyncDtoMapper {

    @Update({
            "update EM_GR_ZSMX_SYNC",
            "set SYNC_STATE = '1'",
            "where ID = #{id,jdbcType=DECIMAL}"})
    void updateSyncStateById(BigDecimal id);
}

service



@Service

@Transactional(rollbackFor=Exception.class)

public class TestOneServiceImp implements ITestOneService {

@Resource
    TestOneDtoMapper testOneDtoMapper;

    @Resource
    TestTwoDtoMapper testTwoDtoMapper;

    @Resource
    OperationLogDtoMapper operationLogDtoMapper;

    @Resource
    EmGrZsmxSyncDtoMapper emGrZsmxSyncDtoMapper;

    @Resource
    ImpDataDtoMapper impDataDtoMapper;

    @Resource
    EmGrZsmxSyngLogDtoMapper emGrZsmxSyngLogDtoMapper;
@Override

    @Log(methodDesc = "数据导出")

    @Transactional(rollbackFor=Exception.class)
    public void insertEM(EmGrZsmxSyncDto emGrZsmxSyncDto) {

            System.out.println("定时插入进入");
            impDataDtoMapper.insert(emGrZsmxSyncDto);
            emGrZsmxSyncDtoMapper.updateSyncStateById(emGrZsmxSyncDto.getId());
            EmGrZsmxSyngLogDto emGrZsmxSyngLogDto = new EmGrZsmxSyngLogDto();
            emGrZsmxSyngLogDto.setSyncId(emGrZsmxSyncDto.getId());
            emGrZsmxSyngLogDto.setZzbh(emGrZsmxSyncDto.getZzbh());
            emGrZsmxSyngLogDto.setSyncDate(new Date());
            JSONObject jsonObject = JSONObject.fromObject(emGrZsmxSyncDto);
            String jsonStr = jsonObject.toString();
            emGrZsmxSyngLogDto.setSyncContent(jsonStr);
            emGrZsmxSyngLogDtoMapper.insert(emGrZsmxSyngLogDto);
            System.out.println(emGrZsmxSyncDto.getId());
            throw new RuntimeException("运行异常");

    }


}

回滚要有异常产生。你的update有产生异常吗?

我的是两个数据源的,然后创建事务的时候只能创建一个数据源的,默认的是主数据源,然后从数据源的不会创建,可以通过@Transactional(value=“”)指定数据源创建事务,但是只能指定单一的数据源事务,有什么办法可以指定两个数据源的事务啊