1.Spring+SpringMVC+Mybatis的框架组合;
2.使用了org.mybatis.spring.mapper.MapperScannerConfigurer将Mapper接口生成代理注入到Spring
3.当把事务切面配在serive.impl的时候,报错
报错内容为:
org.springframework.util.ClassUtils.isUserLevelMethod(Ljava/lang/reflect/Method;)Z
at org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource.getTransactionAttribut
将事务切面配在dao层的时候,代码正常运行:
我的测试代码如图所示,求各位大神不吝赐教,多谢!!!
声明式的事务管理(Declarative transaction management): 事务配置方式:Java代码 for MySQL --> "dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> ......
答案就在这里:spring 事务问题
----------------------你好,人类,我是来自CSDN星球的问答机器人小C,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。
事务配置的代码拿出来看看!
回复林炳文Evankaka :
<tx:advice id="advice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="*" propagation="SUPPORTS"/>
</tx:attributes>
</tx:advice>
<!-- 配置切面:哪些包的哪些类支持事务==>事物主要存在于serivce层 -->
<aop:config>
<aop:pointcut expression="execution(* cn.ej.sz.service.impl.*.*(..))" id="pointcut"/>
<aop:advisor advice-ref="advice" pointcut-ref="pointcut"/>
</aop:config>
报错的全内容:
Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.util.ClassUtils.isUserLevelMethod(Ljava/lang/reflect/Method;)Z
at org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource.getTransactionAttribute(NameMatchTransactionAttributeSource.java:104)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:270)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at $Proxy12.selectByPrimaryKey(Unknown Source)
at cn.ej.sz.test.MyNewTest.main(MyNewTest.java:22)
你没为
select配置事务啊
java.lang.NoSuchMethodError: org.springframework.util.ClassUtils.isUserLevelMethod(Ljava/lang/reflect/Method;)Z
你spring的相关包引全了吗
可以去参详spring事务配置详解
把
expression="execution(* cn.ej.sz.service.impl.*.*(..))
改为
expression="execution(* cn.ej.sz.service.impl.**.*(..))
试试看