| |
| <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> |
| |
| <property name="dataSource" ref="dataSource"></property> |
| </bean> |
| |
| |
| <tx:advice id="txadvice"> |
| |
| <tx:attributes> |
| |
| <tx:method name="accountMoney" propagation="REQUIRED"/> |
| |
| |
| </tx:attributes> |
| </tx:advice> |
| |
| |
| <aop:config> |
| |
| <aop:pointcut id="pt" expression="execution(* org.example.demo07.service.UserService.*(..))"/> |
| |
| <aop:advisor advice-ref="txadvice" pointcut-ref="pt"/> |
| </aop:config> |
| @Service |
| public class UserService { |
| |
| |
| @Autowired |
| private UserDao userDao; |
| |
| |
| public void accountMoney() { |
| userDao.reduceMoney(); |
| |
| int i = 10/0; |
| userDao.addMoney(); |
| } |
| |
| } |
| @Test |
| public void testAccount() { |
| ApplicationContext context = |
| new ClassPathXmlApplicationContext("bean1.xml"); |
| UserService userService = context.getBean("userService", UserService.class); |
| userService.accountMoney(); |
| } |
| 信息: {dataSource-1} inited |
| |
| java.lang.ArithmeticException: / by zero |
| |
| at org.example.demo07.service.UserService.accountMoney(UserService.java:18) |
| at org.example.demo07.service.UserService$$FastClassBySpringCGLIB$$a72641b.invoke(<generated>) |
| at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) |
| at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:779) |
| at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) |
| at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750) |
| at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123) |
| at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388) |
| at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119) |
| at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) |
| at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750) |
| at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97) |
| at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) |
| at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750) |
| at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692) |
| at org.example.demo07.service.UserService$$EnhancerBySpringCGLIB$$97888a1a.accountMoney(<generated>) |
| at org.example.demo07.test.Test1.testAccount(Test1.java:15) |
| at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) |
| at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) |
| at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) |
| at java.base/java.lang.reflect.Method.invoke(Method.java:566) |
| at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) |
| at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) |
| at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) |
| at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) |
| at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) |
| at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) |
| at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) |
| at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) |
| at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) |
| at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) |
| at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) |
| at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) |
| at org.junit.runners.ParentRunner.run(ParentRunner.java:363) |
| at org.junit.runner.JUnitCore.run(JUnitCore.java:137) |
| at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) |
| at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) |
| at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:221) |
| at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54) |
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术