关于Spring事务不起作用,哪位能帮忙看看啊,谢谢。
真实的代码如下,事务不起作用。往下继续看,起作用。
针对doPost和doExecute做了事务配置
<tx:method name="doExecute" propagation="REQUIRED" />
--------------------------------
public class EntryServlet extends HttpServlet{
public void init(ServletConfig config) throws ServletException {
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
IService service = null;
String newJson=strJson(content,0);
service = (IService)BeanService.getBean("shtg");
str=service.doExecute(newJson);//对应Shtg类
newJson=strJson(content,1);
service = (IService)BeanService.getBean("jyztUpdate");
str=service.doExecute(newJson); //对应JyztUpdate 类
}
public void destroy(){
}
}
public class Shtg{
public String doExecute(String jsonStr) throws RuntimeException {
String sql= "update GadwRyXx set jyzt = :jyzt,kyzt='Addd' where guid = :guid and kyzt = '1'";
baseDao.update(sql, parameters);
}
}
public class JyztUpdate{
public String doExecute(String jsonStr) throws RuntimeException {
baseDao.saveObj(gsh);
}
}
-------------------------------------------------------------------------------------
如果将代码变更下,事务就起作用。
public class EntryServlet extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
IService service = null;
String newJson=strJson(content,0);
service = (IService)BeanService.getBean("shtg");
str=service.doExecute(newJson);//对应Shtg类
//newJson=strJson(content,1);
//service = (IService)BeanService.getBean("jyztUpdate");
//str=service.doExecute(newJson); //对应JyztUpdate 类
}
}
public class Shtg{
public String doExecute(String jsonStr) throws RuntimeException {
baseDao.saveObj(gsh);//注意,此处将保存写在Shtg类的doExecute方法,事务就起作用
String sql= "update GadwRyXx set jyzt = :jyzt,kyzt='Addd' where guid = :guid and kyzt = '1'";
baseDao.update(sql, parameters);
}
}