代理异常
Caused by: org.springframework.messaging.MessagingException: Exception thrown while invoking com.mmtvip.frontprovider.mq.ReceiverServer#receiveR00001[1 args]; nested exception is java.lang.IllegalStateException: The mapped handler method class 'com.mmtvip.frontprovider.mq.ReceiverServer$$EnhancerBySpringCGLIB$$bd47ad77' is not an instance of the actual endpoint bean class 'com.mmtvip.frontprovider.mq.ReceiverServer$$EnhancerBySpringCGLIB$$7cbf057b'. If the endpoint requires proxying (e.g. due to @Transactional), please use class-based proxying.
出现原因
Spring Aop默认使用的JDK动态代理,而项目中用到了CGLIB代理,产生冲突。
引发问题
1.@scheduled 定时任务不执行
2.@StreamListener 监听报错,MQ消息接收不到。
解决办法
# AOP
# 开启aop(默认为true)
spring.aop.auto=true
# 开启CGLib代理(true:启用cglib代理,false:启用jdk代理,默认为false)
spring.aop.proxy-target-class=true
另外需要在代理类上加@Aspect (作用是把当前类标识为一个切面供容器读取)
proxy-target-class标签的实现原理
打开Spring-aop包里,META-INF下的spring.handlers
http://www.springframework.org/schema/aop=org.springframework.aop.config.AopNamespaceHandler
</