`
Eric.Yan
  • 浏览: 318359 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Spring AOP+0 formal unbound in pointcut

阅读更多

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

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics