Spring MVC下对Controller 的AOP切面
来源:互联网 发布:learning python中文版 编辑:程序博客网 时间:2024/06/05 08:31
Spring MVC加载的是WebApplicationContext而不是ApplicationContext,问题就在这,应该把schema和加载加到 spring-mvc.xml,也就是
WebApplicationContext.xml中。
1.添加配置如下:
<aop:config>
<aop:aspect id="serviceAop" ref="aaa">
<aop:pointcut id="servicePointCut"
expression="execution(* com.controller.*.*(..))" />
<aop:around pointcut-ref="servicePointCut" method="doArount" />
</aop:aspect>
</aop:config>
<bean id="aaa" class="com.ControllerProxy">
</bean>
以 <aop:pointcut id="serviceMethod" expression="execution(* *..*Service.*(..))" />为例讲解
首先:这个表达式是分为4块的,即:方法返回类型 包 +(子包)+ 方法名 + 参数个数或者类型
1、第一个 * 表示:对任意的返回类型方法进行匹配
2、第二个 * 表示: 对任意的包并且包的最后是以Service结尾的包
3、第三个 * 表示: 对任意的方法名进行匹配
4、第四个(..)表示: 通配,即方法中可以有0个或者多个参数,如果想执行参数为2个,即(*, String)表示2个参数,第二个参数为String类型。
2. aop类如下:
public class ControllerProxy {
public Object doArount(ProceedingJoinPoint point) throws Throwable {
// 返回对象
Object ret = null;
// 获得返回对象类型
Signature signature = point.getSignature();
MethodSignature methodSignature = (MethodSignature) signature;
Method method = methodSignature.getMethod();
String className = methodSignature.getDeclaringType().getSimpleName();
String methodName = method.getName();
......
return ret;
}
- Spring MVC下对Controller 的AOP切面
- Spring AOP 对Spring MVC的Controller切面拦截不起作用
- spring aop 如何切面到mvc 的controller
- Spring MVC 注解下Controller 的AOP
- Spring MVC 注解下Controller 的AOP
- Spring AOP切面对Controller中的方法切点不起作用
- Spring中对Controller层进行AOP切面
- Spring mvc 对Controller配置AOP
- springmvc中aop对controller切面编程
- Spring的切面 AOP
- Spring的面向切面AOP
- Spring的AOP切面编程
- Spring的AOP切面编程
- spring aop 到mvc 的controller配置不起作用
- spring aop 拦截spring mvc controller
- spring4.x aop拦截spring mvc controller
- aop切面配置不起作用引发的spring容器和spring mvc容器关系学习
- spring mvc的Controller
- 打开相册相机上传照片代码
- 国内外三个不同领域巨头分享的Redis实战经验及使用场景
- 图像模拟添加(产生)椒盐噪声的OpenCV代码!
- jquery radio 总结
- HTML入门笔记
- Spring MVC下对Controller 的AOP切面
- BZOJ4403 序列统计
- 【Scala】高阶函数和柯里化
- 降维 Dimensionality Reduction
- oracle中查询表中时间字段和系统时间的差值
- 对汇编课的认识
- C#中lambda表达式浅析
- CentOS7之搭建lnmp环境
- html中body的事件onload定义的函数失效