---
title: "Spring AOP+0 formal unbound in pointcut"
author: "Eric.Yan"
date: "2013-04-17T20:06:25Z"
tags: []
categories: ["企业架构"]
slug: "spring-aop-0-formal-unbound-in-pointcut"
draft: false
lastmod: "2013-04-17T20:06:25Z"
id: 1849120
url: "https://eric-yan.iteye.com/blog/1849120"
---

spring的AOP配置

参考下边这个连接，写的很详尽，不管是利用配置文件配置，还是利用注解的方式完成，一目了然。  
[**http://blog.chinaunix.net/uid-21547257-id-97998.html**](http://blog.chinaunix.net/uid-21547257-id-97998.html)

 

(1)我在学习过程中不管是用Aspect语法注解配置，还是用Spring的&lt;aop:...&gt;命名空间，都会报这么  
一个错误：  
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://www.iteye.com/problems/13707)  
[http://blog.csdn.net/llbupt/article/details/6611901](http://blog.csdn.net/llbupt/article/details/6611901)  
[http://www.myexception.cn/j2ee/390894.html](http://www.myexception.cn/j2ee/390894.html)  
[http://blog.163.com/rettar@126/blog/static/121650342200961611204525/](http://blog.163.com/rettar@126/blog/static/121650342200961611204525/)  
[http://www.linuxidc.com/Linux/2012-01/51270.htm](http://www.linuxidc.com/Linux/2012-01/51270.htm)

(2)我把我用到的几种正确的配置贴出来一起学习下：  
方法一：  
用&lt;aop:..&gt;的命名空间  
&lt;aop:config proxy-target-class="true"&gt;  
     &lt;aop:pointcut id="controllerPointcut" expression="execution(* com.citi.oprisk.mca.web.controller.\*.\*\_ProxyService(..)) and args(name)"/&gt;  
     &lt;aop:aspect ref="mcaControllerMethodExecutionAdvice"&gt;  
       &lt;aop:before pointcut-ref="controllerPointcut" arg-names="name" method="invokeProxy"/&gt;  
     &lt;/aop:aspect&gt;  
&lt;/aop:config&gt;

注意参数的写法

方法二：  
&lt;bean id="exceptionHandlerPointCut" class="org.springframework.aop.aspectj.AspectJExpressionPointcut"&gt;  
      &lt;property name="expression" value="execution(* com.citi.oprisk.mca.web.controller.\*.\*\_ProxyService(..))"&gt;&lt;/property&gt;  
&lt;/bean&gt;  
&lt;bean id="exceptionHandlerAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor"&gt;  
      &lt;property name="pointcut" ref="exceptionHandlerPointCut"&gt;&lt;/property&gt;  
      &lt;property name="advice" ref="mcaControllerMethodExecutionAdvice"&gt;&lt;/property&gt;  
&lt;/bean&gt;  
不用注解，不用&lt;aop:...&gt;，这么写也是可以的

方法三：  
注解方式；

(3)expression表达式详细解释：  
execution(* com.citi.oprisk.mca.web.controller.\*.\*\_ProxyService(..))  
整个表达式的意思是com.citi.oprisk.mca.web.controller包下所有以\_ProxyService结尾的方法；  
第一个\*代表所有的返回值类型  
第二个\*代表所有的类  
第三个\*代表类所有方法  
最后一个..代表所有的参数  
更多详细参考：[http://zhidao.baidu.com/question/497318436.html](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://www.blogjava.net/cmzy/archive/2008/08/09/220910.html)  
[http://cmzy.iteye.com/blog/231802](http://cmzy.iteye.com/blog/231802)