1

我正在开发 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>

是在在 SO 上找到类似问题后添加的proxy-target-class="true",但它似乎对我的情况没有做任何事情。

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 {...}

我试图拦截的方法是公开的。

我不确定还包括什么。我用谷歌搜索了异常,代理,检查了切入点表达式。任何帮助将非常感激。

编辑:

我将 cglib 包含在项目的 ivy 配置中,并按如下方式设置 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>

仍然得到同样的例外。

4

1 回答 1

2

伙计,我认为你必须把

<aop:aspectj-autoproxy proxy-target-class="true"/>

在 servlet-config.xml 而不是 aop-config.xml 中要在相同的 bean 上下文中,你想在它上面使用 AOP className

于 2013-08-22T12:40:11.840 回答