Spring Cloud 动态代理异常处理

代理异常

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</
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值