【发布时间】:2013-08-16 15:08:37
【问题描述】:
我正在开发一个 Spring MVC Web 应用程序,并且正在尝试为特定方法设置 AOP 包装器。我在aop-config.xml 中有以下内容:
<bean name="callCatcher" class="com.business.project.aop.callCatcher"/>
<aop:config proxy-target-class="true">
<aop:pointcut expression="execution(* com.business.project.util.className.methodName(..))" id="catchCall"/>
<aop:advisor advice-ref="callCatcher" pointcut-ref="catchCall"/>
</aop:config>
proxy-target-class="true" 是在在 SO 上找到类似问题后添加的,但它似乎对我的情况没有任何帮助。
aop-config.xml 包含在我的servlet-config.xml 中:
<import resource="aop-config.xml"/>
当我尝试部署它时,出现以下异常:
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.business.project.util.className' to required type 'org.springframework.aop.Pointcut' for property 'pointcut'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.business.project.util.className] to required type [org.springframework.aop.Pointcut] for property 'pointcut': no matching editors or conversion strategy found
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:463)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:494)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:488)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1433)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1392)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1128)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
... 37 more
我试图拦截的类被自动连接为使用它的类的属性。所以我想知道这是否是问题的一部分。没什么特别的:
public class className implements ApplicationContextAware {...}
我试图拦截的方法是公开的。
我不确定还包括什么。我用谷歌搜索了异常,代理,检查了切入点表达式。任何帮助将不胜感激。
编辑:
我在项目的 ivy 配置中包含了 cglib,并设置 aop-config 如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">
<aop:aspectj-autoproxy proxy-target-class="true"/>
<bean name="callCatcher" class="com.business.project.aop.EditorActionLogger"/>
<aop:config proxy-target-class="true">
<aop:pointcut expression="execution(* com.business.project.util.className.methodNAme(..))" id="callCatcher"/>
<aop:advisor advice-ref="editorActionLogger" pointcut-ref="timeslotReloader"/>
</aop:config>
</beans>
仍然遇到同样的异常。
【问题讨论】:
-
我……真的不知道。我不这么认为;我们使用 Ivy 进行依赖管理,我检查了配置文件并没有看到 cglib 的任何内容。
-
如果你强制使用 cglib 代理而不是
Spring应该没问题。可以添加 ivy see here 的依赖吗? -
我检查了我们的常春藤仓库,我们有 cglib 2.1.3;我将其添加为依赖项,并按照问题中的 aop-config 重新部署它,它给了我同样的错误。我还需要做些什么来强制它使用 cglib 而不是 Spring?
-
尝试从here添加
<aop:aspectj-autoproxy proxy-target-class="true"/> -
我会先尝试让 cglib 工作。看到这个related post
标签: spring aop spring-aop