Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

应用依赖nacos-spring-context版本从0.3.6升至1.1.0之后,@NacosInjected注入bean时抛异常 #258

Open
zrlw opened this issue May 16, 2021 · 4 comments

Comments

@zrlw
Copy link

zrlw commented May 16, 2021

Issue Description

Type: bug report

Describe what happened (or what feature you want)

程序里有@component组件使用了@NacosInjected注解,用nacos-spring-context 0.3.6版本时一切正常,升到1.1.0之后,启动抛ClassCastException,异常位置在AnnotationNacosInjectedBeanPostProcessor.java 145行,提示com.sun.proxy.$Proxy113 cannot be cast to java.util.Map,跟踪到此发现attributes对象是个map,key="properties"对应的value对象类型是@NacosProperties,转Map注定异常。
写了个测试工程,pom.xml有dubbo(测试了2.7.5、2.7.9、2.7.11三个版本)就会出现上述异常,去掉dubbo依赖就运行正常。
将nacos-spring-context版本降至0.3.6,也恢复正常。

Tell us your environment

spring-boot-starter-test 2.2.6.RELEASE
spring-boot-starter-log4j2 2.2.6.RELEASE
spring-boot-starter-aop 2.2.6.RELEASE
nacos client 1.4.2
dubbo 2.7.5 / 2.7.9 / 2.7.11
lombok 1.18.12
nacos-spring-context 1.1.0

@zrlw
Copy link
Author

zrlw commented May 19, 2021

原因是dubbo和nacos-spring-context依赖的com.alibaba.spring/spring-context-support版本不同而且不兼容所致,需要排除dubbo的依赖版本,但是不知道这样做有没有其他副作用。

@zrlw
Copy link
Author

zrlw commented May 19, 2021

发现有副作用,排除掉dubbo依赖的spring-context-support版本之后,注入dubbo的@reference注解就会ClassCastException: java.lang.String cannot be cast to java.lang.Class ( DubboAnnotationUtils.java 95行)

@zrlw
Copy link
Author

zrlw commented Jul 5, 2021

根源是 alibaba的spring-context-support升到1.0.11并没有考虑向前兼容,AbstractAnnotationBeanPostProcessor新增的classValuesAsString,nestedAnnotationsAsMap默认为true,而当前所有dubbo版本的ReferenceAnnotationBeanPostProcessor依赖的是spring-context-support 1.0.10以及之前的版本,dubbo使用spring-context-support 1.0.11时需要将这两个值改为false。
我给dubbo提交了修订:
apache/dubbo#8217

@zk20180228
Copy link

我也有这个问题,真是头疼(后来把nacos-spring-context降级为0.3.6正常)
异常信息:
Caused by: java.lang.ClassCastException: com.sun.proxy.$Proxy8 cannot be cast to java.util.Map,原因是在at com.alibaba.nacos.spring.beans.factory.annotation.AnnotationNacosInjectedBeanPostProcessor.getNacosProperties的145行
环境信息(没有dubbo哦):
nacos-serve:2.0.3
nacos-spring-context:1.1.1
spring.boot.version:2.3.2.RELEASE
nacos-client:1.4.2
spring-context-support:1.0.10
javax-annotation-api:1.3.2
spring-context:5.2.8.RELEASE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants