版权声明:博客知识产权来源命运的信徒,切勿侵权 https://blog.csdn.net/qq_37591637/article/details/88661675
错误背景:
基于ssh框架的javaweb项目
错误代码
package cn.com.service;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import com.opensymphony.xwork2.ActionSupport;
@Repository(value="regedit")
@Scope("prototype")
public class Regedit extends ActionSupport{
private String name;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
@Transactional
public String regedit_user(){
System.out.println("name:"+name);
return "regedit_success";
}
}
解决方案:
1、
注解版本:
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
配置版本:
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
<aop:config proxy-target-class="true">
<cache:annotation-driven proxy-target-class="true"/>
2、去掉@Transactional或者去掉extends ActionSupport
错误原因
@Transactional就是有spring管理,spring管理的对象要生成代理!
proxy-target-class="true"是基于类的管理
proxy-target-class="false"是基于接口的管理 默认是基于接口的管理!
基于接口的管理是抽象类,抽象类不可以生成代理