今天写程序的时候发生了一件怪异的事情,用spring的aop进行拦截action发现总是不成功,代码是从之前已经测试成功的项目中拷贝过来的。后来又试着去拦截其他类竟然成功了
就是说我用spring的拦截器拦截普通类没问题,可是拦截action却拦截不到,有没有告诉告诉我为什么。下面是拦截的配置信息
<bean id="XunGenLog" class="pro.ict.strutslog.LogWriter"></bean>

<aop:config>
<aop:aspect id="logpoint" ref="XunGenLog">
<aop:pointcut id="log" expression="execution         (*com.vega.genealogy.system.album.action.*.*(..))"/>
<aop:before pointcut-ref="log" method="before"/>
<aop:after pointcut-ref="log" method="after"/>
</aop:aspect>
</aop:config>这个配置信息是拦截action操作,其中action包中都是action类,拦截不成功,没有任何消息也没有任何错误提示同样的配置文件
<bean id="XunGenLog" class="pro.ict.strutslog.LogWriter"></bean>

<aop:config>
<aop:aspect id="logpoint" ref="XunGenLog">
<aop:pointcut id="log" expression="execution(* com.vega.genealogy.system.album.services.*.*(..))"/>
<aop:before pointcut-ref="log" method="before"/>
<aop:after pointcut-ref="log" method="after"/>
</aop:aspect>
</aop:config>
这个是拦截数据层的。service里面放的都是dao类。这个可以成功,配置完全相同,唯一不同的就是包不一样。有没有高手指教一下action是不是有什么特别的方法进行拦截啊。还是有其他地方需要特殊配置

解决方案 »

  1.   

    expression="execution (*com.vega这里的*后没空格,其他没看出什么。
      

  2.   

    expression="execution (*com.vega.genealogy.system.album.action.*.*(..))"/>
    *后面少了空格
      

  3.   

      这个我也出现过 我拦截过Servlet也拦截不到
      然后换成业务类就成功了  好像是因为Action执行的时候是调用业务的方法 
      

  4.   

    action一般都是反射调用的,aop拦截不到的
      

  5.   

    和空格没关系。这个问题我感觉是spring代理struts的配置问题。因为上面的配置文件是我从我们公司另外一个项目之间拷贝过来的。那个项目中可以成功拦截到action操作。所以我感觉是spring代理struts的配置文件或者是事务管理的配置问题。有没有哪位朋友遇到过啊。项目的配置文件都是架构师给搭好的。太多了。我根本没办法找。
      

  6.   

    朋友 们。。我也遇到了一个特别棘手的问题。。我也是这样弄的。。能成功的拦截Action 可问题是。。从表单过来的数据 不能出现 “类名.变量名”的形式如果 出现了。。后台就会报异常。。 如果不用这种形式。。系统就可以 正常运行。。因为Struts中。。这样的用法 。。系统可以自动为变量Set值。。这个形式。。我还想依然使用。。我在执行方法之前就打了断点。。也就是说。。在执行Action中的方法之间。。系统就报了异常。。我没有 查到。。Aop在拦截之前 做了什么操作。。楼主看一下。。咱们的问题是不是一个问题啊。。各位大侠们。。有没有好的解决方案啊。。
      

  7.   

    补充一下,异常是这样的:
    2012-11-08 11:02:46 [WARN]-[com.opensymphony.xwork2.ognl.OgnlValueStack:60] Error setting expression 'swfUserVO.pass' with value '[Ljava.lang.String;@1f29905'
    ognl.OgnlException: target is null for setProperty(null, "pass", [Ljava.lang.String;@1f29905)
    at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2239)
    at ognl.ASTProperty.setValueBody(ASTProperty.java:127)
    at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
    at ognl.SimpleNode.setValue(SimpleNode.java:301)
    at ognl.ASTChain.setValueBody(ASTChain.java:227)
    at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
    at ognl.SimpleNode.setValue(SimpleNode.java:301)
    at ognl.Ognl.setValue(Ognl.java:737)
    at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:209)
    at com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue(OgnlValueStack.java:173)
    at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:160)
    at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:151)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:288)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:199)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    很显然。。我们从
    Error setting expression 'swfUserVO.pass' with value '[Ljava.lang.String;@1f29905'
    ognl.OgnlException: target is null for setProperty(null, "pass", [Ljava.lang.String;@1f29905)
    可以 看出。。我在页面表单中,密码文本框的名字是:'swfUserVO.pass' 
    此时如果 Aop不去拦截Action 时,swfUserVO这个实例的pass变量会自动被赋值为用户输入的密码。
    此时如果使用Aop拦截Action 时。执行登录方法之前。这个程序就不行了。。运行不了了
    我从Debug中,可以 看到'swfUserVO.pass' 中,是有值的。。
    哪们高手遇到这个问题啊。。给一个解决方案。
    我试过。。如果表单中。。不出现类名.变量名 的时候 是可以的。。可是这样使用系统会自动SET。这个我还不想停用。。这个应该怎么解决啊。
      

  8.   

    我也正研究这个呢。
    这样写:
    <aop:config proxy-target-class="true">
    ...
    </aop:config>试试!
      

  9.   

    这个方法可以解决spring aop 拦截struts action的问题。