纯手打,转载务请附上本文网址!!!
做自己开发的SSM项目的时候某天打开eclipse的时候突然就显示有org.springframework.transaction.interceptor.TransactionInterceptor.invoke错误,很奇怪不知道是为什么
改完之后记得重新build或者clean项目!
@Service标签和事务都已经配置完毕没什么问题了
Class dependency error 'WResponse' occurred on aspect definition 'Aspect
definition [/warehouse-web/src/main/resources/spring/applicationContext-
trans.xml:39] advise type [after] advise
[org.springframework.transaction.interceptor.TransactionInterceptor.invoke]'
while processing bean 'pageController (17)
[com.warehouse.controller.PageController]'. Check if builder classpath is
complete
applicationContext-trans.xml配置中事务配置如下
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 数据源 -->
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="create*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="select*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 切面 -->
<aop:config>
<aop:advisor advice-ref="txAdvice" pointcut="execution(* com.warehouse.service.*.*(..))"/>
</aop:config>
</beans>
applicationContext-service.xml中包扫描也配置了没问题
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 扫描包,加载service实现类 -->
<context:component-scan base-package="com.warehouse.service"/>
</beans>
后来发现是Service中函数命名的问题,事务中配置的name包含了save*、insert*、add*、create*、delete*、update*、find*、select*、find*、select*、get*,但是我在Service中函数的命名是check开头的,不符合配置中的name。我们需要在applicationContext-trans.xml中添加一个事务名为check*的即可,问题解决
<tx:method name="check*" propagation="SUPPORTS" read-only="true"/>
最后亮一下我的Service内容,注意里面名为check开头的函数与tx事务中配置的对应关系
package com.warehouse.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.warehouse.bean.Userinfo;
import com.warehouse.bean.UserinfoExample;
import com.warehouse.bean.UserinfoExample.Criteria;
import com.warehouse.mapper.UserinfoMapper;
import com.warehouse.service.UserLoginService;
import com.warehouse.utils.MD5;
@Service
public class UserLoginServiceImpl implements UserLoginService{
@Autowired
private UserinfoMapper userinfoMapper;
@Override
public Integer checkUserGetLevel(Userinfo user) throws Exception{
Integer level=-1;
UserinfoExample example=new UserinfoExample();
Criteria criteria=example.createCriteria();
criteria.andUsernameEqualTo(user.getUsername());
criteria.andPasswordEqualTo(MD5.getMD5(user.getPassword()));
List<Userinfo> list=userinfoMapper.selectByExample(example);
if(list.size()>0) {
return list.get(0).getLevel();
}
return level;
}
}