美文网首页java
2020-05-25-问题解决-but was actually

2020-05-25-问题解决-but was actually

作者: logi | 来源:发表于2020-05-25 15:21 被阅读0次

办法

 <aop:aspectj-autoproxy/> 

改为

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

问题

2020-05-25 15:16:36,561 [main] ERROR (TestContextManager:234) - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@57db2b13] to prepare test instance [xxxRerankTest@30b34287]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxxxRerankTest': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'DealRerankStrategy' is expected to be of type 'xxxRerankStrategyImpl.DealRerankStrategy' but was actually of type 'com.sun.proxy.$Proxy31'
    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:321) ~[spring-context-4.3.9.RELEASE.jar:4.3.9.RELEASE]
...

问题原因

Aspect的实现原理是基于接口的动态代理技术,而不是基于实现类的动态代理技术

<aop:aspectj-autoproxy />有一个proxy-target-class属性,默认为false,表示使用jdk动态代理织入增强,当配为<aop:aspectj-autoproxy poxy-target-class="true"/>时,表示使用CGLib动态代理技术织入增强。不过即使proxy-target-class设置为false,如果目标类没有声明接口,则spring将自动使用CGLib动态代理。

reference

  1. https://blog.csdn.net/zx6571269/article/details/79330495

  2. https://blog.csdn.net/jonesAriven/article/details/99545145

  3. https://www.cnblogs.com/dengchengchao/p/11823687.html

  4. https://cloud.tencent.com/developer/article/1383517

相关文章

网友评论

    本文标题:2020-05-25-问题解决-but was actually

    本文链接:https://www.haomeiwen.com/subject/tfpyahtx.html