今天写程序的时候发生了一件怪异的事情,用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是不是有什么特别的方法进行拦截啊。还是有其他地方需要特殊配置
就是说我用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是不是有什么特别的方法进行拦截啊。还是有其他地方需要特殊配置
*后面少了空格
然后换成业务类就成功了 好像是因为Action执行的时候是调用业务的方法
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。这个我还不想停用。。这个应该怎么解决啊。
这样写:
<aop:config proxy-target-class="true">
...
</aop:config>试试!