在Spring MVC中,事务可以加在Controller层
来源:互联网 发布:中海达rtk数据导出 编辑:程序博客网 时间:2024/06/05 17:40
转自:http://blog.csdn.net/mmm333zzz/article/details/45288061
在Spring MVC中,事务可以加在Controller层
一般而言,事务都是加在Service层的,但是爱钻牛角尖的我时常想:事务加在Controller层可不可以。我一直试图证明事务不止可以加在Service层,还可以加在Controller层,但是没有找到有力的论据来支持我这个想法,搞得我一度认为事务只能加在Service层,直到我读过spring官方文档并实践之后,我知道我的想法是对的。
在spring-framework-reference.pdf文档中有这样一段话:
<tx:annotation-driven/> only looks for @Transactional on beans in the same application context it is defined in. This means that, if you put <tx:annotation-driven/> in a WebApplicationContext for a DispatcherServlet, it only checks for @Transactional beans in your controllers, and not your services.
这句话的意思是,<tx:annoation-driven/>只会查找和它在相同的应用上下文件中定义的bean上面的@Transactional注解,如果你把它放在Dispatcher的应用上下文中,它只检查控制器上的@Transactional注解,而不是你services上的@Transactional注解。
于是,我将事务配置定义在Spring MVC的应用上下文(*-servlet.xml)中,将@Transactional注解打在Controller上,终于事务起作用了。
综上,在Spring MVC中,事务不仅可以加在Service层,同样也可以加在Controller层(虽然不推荐这么做,但至少满足了我的好奇心,(*^__^*) 嘻嘻……)。
注意: Controller层只支持 @Transactional 注解式事务!
转自:http://blog.csdn.net/mmm333zzz/article/details/45288061
在Spring MVC中,事务可以加在Controller层
一般而言,事务都是加在Service层的,但是爱钻牛角尖的我时常想:事务加在Controller层可不可以。我一直试图证明事务不止可以加在Service层,还可以加在Controller层,但是没有找到有力的论据来支持我这个想法,搞得我一度认为事务只能加在Service层,直到我读过spring官方文档并实践之后,我知道我的想法是对的。
在spring-framework-reference.pdf文档中有这样一段话:
<tx:annotation-driven/> only looks for @Transactional on beans in the same application context it is defined in. This means that, if you put <tx:annotation-driven/> in a WebApplicationContext for a DispatcherServlet, it only checks for @Transactional beans in your controllers, and not your services.
这句话的意思是,<tx:annoation-driven/>只会查找和它在相同的应用上下文件中定义的bean上面的@Transactional注解,如果你把它放在Dispatcher的应用上下文中,它只检查控制器上的@Transactional注解,而不是你services上的@Transactional注解。
于是,我将事务配置定义在Spring MVC的应用上下文(*-servlet.xml)中,将@Transactional注解打在Controller上,终于事务起作用了。
综上,在Spring MVC中,事务不仅可以加在Service层,同样也可以加在Controller层(虽然不推荐这么做,但至少满足了我的好奇心,(*^__^*) 嘻嘻……)。
注意: Controller层只支持 @Transactional 注解式事务!
在Spring MVC中,事务可以加在Controller层
一般而言,事务都是加在Service层的,但是爱钻牛角尖的我时常想:事务加在Controller层可不可以。我一直试图证明事务不止可以加在Service层,还可以加在Controller层,但是没有找到有力的论据来支持我这个想法,搞得我一度认为事务只能加在Service层,直到我读过spring官方文档并实践之后,我知道我的想法是对的。
在spring-framework-reference.pdf文档中有这样一段话:
<tx:annotation-driven/> only looks for @Transactional on beans in the same application context it is defined in. This means that, if you put <tx:annotation-driven/> in a WebApplicationContext for a DispatcherServlet, it only checks for @Transactional beans in your controllers, and not your services.
这句话的意思是,<tx:annoation-driven/>只会查找和它在相同的应用上下文件中定义的bean上面的@Transactional注解,如果你把它放在Dispatcher的应用上下文中,它只检查控制器上的@Transactional注解,而不是你services上的@Transactional注解。
于是,我将事务配置定义在Spring MVC的应用上下文(*-servlet.xml)中,将@Transactional注解打在Controller上,终于事务起作用了。
综上,在Spring MVC中,事务不仅可以加在Service层,同样也可以加在Controller层(虽然不推荐这么做,但至少满足了我的好奇心,(*^__^*) 嘻嘻……)。
注意: Controller层只支持 @Transactional 注解式事务!
0 0
- 在Spring MVC中,事务可以加在Controller层
- 在Spring MVC中,事务可以加在Controller层
- 在Spring MVC中,事务可以加在Controller层
- 在Spring MVC中,事务可以加在Controller层
- 在Spring MVC中,事务可以加在Controller层
- Spring MVC中,事务是否可以加在Controller层
- spring在controller层声明事务
- 关于spring在controller层的事务操作
- 在Spring MVC controller中配切点
- 在spring MVC的controller中获取ServletConfig
- spring mvc,在controller中获取属性文件的值
- 在spring mvc应用中创建第一个Controller
- spring springmvc 将事物管理(@Transactional)分别加在 controller和service层
- spring springmvc 将事物管理(@Transactional)分别加在 controller和service层
- 在Spring中配置Service层方法的事务
- 在spring mvc中实现在Controller中进行页面跳转有两种方式
- Asp.net Mvc Framework可以在Controller中使用的Url.Action方法
- Asp.net Mvc Framework可以在Controller中使用的Url.Action方法
- Redis特性一览
- 数据结构----归并排序(转载)
- Zybo板运行Linux系统原理总结
- 洛谷P2480 [SDOI2010]古代猪文
- Mesos超配:让集群利用率可以达到100%
- 在Spring MVC中,事务可以加在Controller层
- Storm运行原理探索
- poj 1258 Agri-Net 【最小生成树-Kruskal】
- phpstorm之自定义代码碎片(tab键自动填充代码)
- JBoss Web和 Tomcat的区别
- Andriod自定义View三:getWidth()与getMeasuredWidth()的区别
- "小密圈"来了,带你了解更多开发技术,和我每天一起进步!
- 面向对象的三大基本特性,五大基本原则
- bootstrap表单宽度设置