环境:
spring boot :2.1.8.RELEASE
nutz boot : 1.r.66
数据库:Mysql
数据库连接池:druid
问题:spring 托管事务未生效
@SpringBootApplication
@EnableTransactionManagement
@ServletComponentScan
@EnableScheduling
public class MyApplication extends SpringBootServletInitializer{
@Override
protected SpringApplicationBuilder configure(MyApplication builder) {
return super.configure(builder);
}
public static void main(String[] args) {
SpringApplication.run(SwiftApplication.class, args);
}
}
@Component
public class DaoConfig {
@Autowired
private Dao dao;
@PostConstruct
public void initNutzDaoWithSpringTransaction() {
NutDao ss = (NutDao) this.dao;
ss.setRunner(new SpringDaoRunner());
}
}
@Transactional
public void updateAndSave(BizData bizData1, BizData bizData2) {
dao.update(bizData1); // 直接入库,未回滚
int a = 0;
int b = 1/a; // 异常
dao.insert(bizData2);
}
异常日志
java.lang.ArithmeticException: / by zero
at com.saicfc.swift.service.impl.FileServiceImpl.updateAndSave(FileServiceImpl.java:98)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:205)
at com.sun.proxy.$Proxy70.createLocalFile(Unknown Source)
at com.saicfc.swift.service.impl.FileServiceImpl.createMsgFiles(FileServiceImpl.java:70)
at com.saicfc.swift.cron.SendAndReceiveCron.createMsgFile(SendAndReceiveCron.java:65)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
at java.util.concurrent.FutureTask.run(FutureTask.java)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
断点第一行更新后,直接入库了,出错未回滚,请大神指点~~