解决Spring MVC 对AOP不起作用的问题
2024-08-29 04:10:32
用的是 SSM3的框架 Spring MVC 3.1 + Spring 3.1 + Mybatis3.1
第一种情况:
Spring MVC 和 Spring 整合的时候,SpringMVC的springmvc.xml文件中 配置扫描包,不要包含 service的注解,Spring的applicationContext.xml文件中
配置扫描包时,不要包含controller的注解,如下所示:
SpringMVC的xml配置:
<context:component-scan base-package="com.insigma">
<context:exclude-filter
type="annotation" expression="org.springframework.stereotype.Service"/>
type="annotation" expression="org.springframework.stereotype.Service"/>
</context:component-scan>
启动时的配置文件,包含组件扫描、映射以及设置参数,让不扫描带有注解的类。为什么要这样设置?因为与不是同时加载,如果不进行这样的设置,那么,spring@ServiceapplicationContext.xmlServicecglibServiceapplicationContext 中的事务配置不起作用,发生异常时,无法对数据进行回滚。以上就是原因所在。
同样的在Spring的xml配置如下:
同样的在Spring的xml配置如下:
<context:component-scan
base-package="com.insigma">
base-package="com.insigma">
<context:exclude-filter
type="annotation" expression="org.springframework.stereotype.Controller"/>
type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
@Controllerspringmvc.xml
注意以上几点就OK了。
这是转载文章...........
最新文章
- iOS创建安全的单例
- LR手动关联新手总结
- Yii2的邮件配置
- 瘟疫公司中国版(Android)手动破解内购
- Java多线程编程核心技术---对象及变量的并发访问(二)
- JAVA敏捷开发环境搭建
- 我存在,你深深的循环里--从反射看JSON死循环
- 【转】https,https的本地测试环境搭建,asp.net结合https的代码实现,http网站转换成https网站之后遇到的问题
- java后台正则验证
- MySQL中char、varchar和text的区别
- WebApi2官网学习记录---Media Formatters
- GDKOI2016 游记
- Using variables inside Postman and Collection Runner
- 解析JavaScript中的sort()排序方法以及原理
- 禁止root登陆sshd/并修改默认端口号
- [agc016B][Colorful Hats]
- Android百大框架排行榜
- 【ASP.NET】Layout使用详解
- NOIP2018游记(更新完毕)
- 理解mvn命令
热门文章
- yum search/intall, Error: xz compression not available
- 如何重启mysql服务
- arm linux 下移植busybox 的tftp
- resize2fs: Bad magic number in super-block while trying to open /dev/centos/root Couldn&#39;t find valid filesystem superblock
- Spring Boot发布和调用RESTful web service
- java中Swing编程再度练习篇
- Linux打包下载命令
- 1 ignite核心特性
- IOCP编程原理(转)
- 用原生JS和html5进行视频截图并保存到本地