Roh*_*hit 1 proxy spring spring-aop
我正在尝试在现有的spring项目中配置一个建议.以下配置适用于单个程序包,但是当切入点表达式尝试在所有程序包上应用该通知时,它会给出以下错误.
我的配置:
<aop:config>
<aop:pointcut id="loggingPointcut" expression="execution(* com.abc.businessprocess.operation..*.execute(..))" />
<aop:advisor id="methodLoggingAdvisor" advice-ref="methodLoggingAdvice" pointcut-ref="loggingPointcut" />
</aop:config>
Run Code Online (Sandbox Code Playgroud)
我也尝试了注释,但它给出了相同的错误.即使在使用它给出相同的错误后,我也尝试使用CGLIB.
错误:
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy12 implementing com.fmr.ast.common.businessprocess.util.Timeable,com.fmr.ast.common.businessprocess.operation.Operation,com.fmr.commons.taskmanager.core.Task,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.fmr.ips.businessprocess.operation.goalsetup.GetLeveledIRGExpInc] for property 'getRawDetailedLeveledExpInc'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy12 implementing com.fmr.ast.common.businessprocess.util.Timeable,com.fmr.ast.common.businessprocess.operation.Operation,com.fmr.commons.taskmanager.core.Task,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.fmr.ips.businessprocess.operation.goalsetup.GetLeveledIRGExpInc] for property 'getRawDetailedLeveledExpInc': no matching editors or conversion strategy found
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:391)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1289)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1250)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
... 33 more
Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy12 implementing com.fmr.ast.common.businessprocess.util.Timeable,com.fmr.ast.common.businessprocess.operation.Operation,com.fmr.commons.taskmanager.core.Task,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.fmr.ips.businessprocess.operation.goalsetup.GetLeveledIRGExpInc] for property 'getRawDetailedLeveledExpInc': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:231)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:386)
... 37 more
Run Code Online (Sandbox Code Playgroud)
查看异常跟踪,这是我怀疑的:
GetLeveledIRGExpInc是实现三个接口的具体类:Timeable,Operation,Task.您在上下文中声明了这种类型的bean,由于您的AOP配置而被代理.这意味着bean的运行时类型将不再存在GetLeveledIRGExpInc,它将是$Proxy12(JDK代理)仍然实现上述三个接口,但不是具体类的子类型GetLeveledIRGExpInc.
在您的上下文中有另一个bean需要将此类型的bean注入到名为的属性中getRawDetailedLeveledExpInc.当Spring尝试将代理bean注入该属性时,它会失败,因为该属性的类型与bean的运行时类型不兼容.
基本问题是您尝试使用JDK代理机制应用非常通用的日志记录方面,该机制只能建议在接口上声明的方法.尝试使用,<aop:config proxy-target-class="true">以便也可以建议没有实现接口的类.这将解决上述详细问题,因为生成的CGLIB代理GetLeveledIRGExpInc实际上将是它的子类型.(不要忘记将cglib添加到您的依赖项中以使其工作.)
| 归档时间: |
|
| 查看次数: |
4088 次 |
| 最近记录: |