spring的AOP配置
参考下边这个连接,写的很详尽,不管是利用配置文件配置,还是利用注解的方式完成,一目了然。
http://blog.chinaunix.net/uid-21547257-id-97998.html
(1)我在学习过程中不管是用Aspect语法注解配置,还是用Spring的<aop:...>命名空间,都会报这么
一个错误:
0 formal unbound in pointcut
搜了很多资料,几经波折,都说是expression表达式方法参数匹配的问题,但一直都没有找到不报错
的正确的配置,有问题的expression表达式为:
execution(* com.citi.oprisk.mca.web.controller.*.*_ProxyService(..))
意为拦截此包下所有以_ProxyService结尾的方法,
改过后不报错的表达式为:
execution(* com.citi.oprisk.mca.web.controller.*.*_ProxyService(..)) and args(name);
关于这个问题搜到一些资料:
http://www.iteye.com/problems/13707
http://blog.csdn.net/llbupt/article/details/6611901
http://www.myexception.cn/j2ee/390894.html
http://blog.163.com/rettar@126/blog/static/121650342200961611204525/
http://www.linuxidc.com/Linux/2012-01/51270.htm
(2)我把我用到的几种正确的配置贴出来一起学习下:
方法一:
用<aop:..>的命名空间
<aop:config proxy-target-class="true">
<aop:pointcut id="controllerPointcut" expression="execution(* com.citi.oprisk.mca.web.controller.*.*_ProxyService(..)) and args(name)"/>
<aop:aspect ref="mcaControllerMethodExecutionAdvice">
<aop:before pointcut-ref="controllerPointcut" arg-names="name" method="invokeProxy"/>
</aop:aspect>
</aop:config>
注意参数的写法
方法二:
<bean id="exceptionHandlerPointCut" class="org.springframework.aop.aspectj.AspectJExpressionPointcut">
<property name="expression" value="execution(* com.citi.oprisk.mca.web.controller.*.*_ProxyService(..))"></property>
</bean>
<bean id="exceptionHandlerAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
<property name="pointcut" ref="exceptionHandlerPointCut"></property>
<property name="advice" ref="mcaControllerMethodExecutionAdvice"></property>
</bean>
不用注解,不用<aop:...>,这么写也是可以的
方法三:
注解方式;
(3)expression表达式详细解释:
execution(* com.citi.oprisk.mca.web.controller.*.*_ProxyService(..))
整个表达式的意思是com.citi.oprisk.mca.web.controller包下所有以_ProxyService结尾的方法;
第一个*代表所有的返回值类型
第二个*代表所有的类
第三个*代表类所有方法
最后一个..代表所有的参数
更多详细参考:http://zhidao.baidu.com/question/497318436.html
(4)使用ProxyFactoryBean创建AOP代理:http://doc.javanb.com/spring-framework-reference-zh-2-0-5/ch07s05.html
Spring AOP ProxyFactoryBean Example:http://www.roseindia.net/tutorial/spring/spring3/aop/proxyfactorybeanexample.html
Spring的切入点:
http://www.blogjava.net/cmzy/archive/2008/08/09/220910.html
http://cmzy.iteye.com/blog/231802
相关推荐
SpringMVC+springAOP+spring security+Hibernate整合实例代码,包含框架jar包
基于Cglib简单实现Spring体系(Ioc+Aop+Mvc)基于Cglib简单实现Spring体系(Ioc+Aop+Mvc)基于Cglib简单实现Spring体系(Ioc+Aop+Mvc)基于Cglib简单实现Spring体系(Ioc+Aop+Mvc)基于Cglib简单实现Spring体系(Ioc+Aop+Mvc)...
Spring AOP + SpringMVC +Mybatis做动态数据源,实现读写分离Spring AOP + SpringMVC +Mybatis做动态数据源,实现读写分离Spring AOP + SpringMVC +Mybatis做动态数据源,实现读写分离
工程介绍:SpringBoot项目脚手架,利用spring aop+java反射实现自定义注解校验参数 源码里有使用都例子在DemoContorller example1:校验userName参数必填 @CheckParams(notNull = true) private String userName;...
项目描述 学生成绩管理系统,有三...spring boot+spring mvc+mybatis+layui+jquery+thymeleaf http://localhost:8080/Sys/loginView 管理员账号 admin admin 老师登录 2020031920 111111 学生账号登录 20200319 111111
springaop的注解和xml配置,也包括aop处理参数的方法
一个简单的采用自定义注解结合SpringAop实现方法执行的权限管理,这个demo中并没有涉及到与数据库的交互和业务代码,用户权限在登陆时采用简单的手动初始化。该demo用的jdk1.7编译,Spring4.0版本,只想通过这个demo...
以公司订单管理的模型为例(大部分步骤和业务了逻辑已经删除,只保存AOP注解这一部分)Spring AOP
NULL 博文链接:https://java-script.iteye.com/blog/1160745
SpringBoot+AOP+TraceID.pdf
NULL 博文链接:https://miaoxianjie.iteye.com/blog/2067308
NULL 博文链接:https://tuoxinquyu.iteye.com/blog/1465155
面向切面编程(Aspect-Oriented Programming,AOP):Spring支持面向切面编程,允许开发者将横切关注点(如日志、事务、安全性等)从核心业务逻辑中分离出来,并以模块化的方式进行重用。这样可以提高代码的可维护性...
该软件依赖包,为实例spring aop实现Hinernate事务操作软件包
开发Spring+AOP的使用库文件,spring-aop-5.2.8.RELEASE.jar,aspectjrt-1.9.1.jar,aspectjweaver-1.9.5.jar等
手写spring框架ioc+aop+mvc
NULL 博文链接:https://tuoxinquyu.iteye.com/blog/1465187
缘起需求:需要使用Spring来实现一个Cache简单的解决方案,具体需求如下:使用任意一个现有开源Cache Framework,要求可以Cache系统中Service或者DAO层的get/find等方法返回结果,如果数据更新(使用Create/update/...
spring-aop-5.3.22.jar Spring AOP provides an Alliance-compliant aspect-oriented programming implementation allowing you to define method interceptors and pointcuts to cleanly decouple code that ...