为什么分层结构,Spring 事务就不起作用呢,如果不分层就起作用。
public class EntryServlet extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
。。。
Tool.doExecute(json);
}
}
public class Tool {
public static String doExecute(String json) throws Exception {
.....
str=service1.save(newJson);//往表1插入数据
str=service2.save(newJson);//往表2插入数据
}
}
针对EntryServlet的doPost进行了事务配置
针对Tool的doExecute进行了事务配置
针对save进行了事务配置
以上是分层实现的,为什么事务不起作用呢。
如果我不分层实现,比如按照下面这种方式,对 entry进行事务配置,就起作用
public class classEnery{
public entry(){
this.doexece();
}
public void doexece(){
save1();//往表1插入数据
save2();//往表2插入数据
}
}