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

Dubbo 2.7.5, 2.7.9, 2.7.11, 2.7.12 are incompatiable with nacos-spring-context 1.1.0 #7797

Closed
zrlw opened this issue May 19, 2021 · 13 comments
Closed
Assignees
Milestone

Comments

@zrlw
Copy link
Contributor

zrlw commented May 19, 2021

Environment

  • Dubbo version: 2.7.5 or 2.7.9 or 2.7.11 or 2.7.12
  • Operating System version: centos7
  • Java version: 1.8
  • nacos-spring-context 1.1.0

Steps to reproduce this issue

create a maven spring-boot test application which pom.xml has dubbo first and nacos-spring-context 1.1.0 later,
with dubbo which depend on spring-context-support 1.0.10:
a ClassCastException - com.sun.proxy.$Proxy...NNN... cannot be cast to java.util.Map - will be throwed at AnnotationNacosInjectedBeanPostProcessor.java line 145.
with dubbo which depend on spring-context-support 1.0.8 or less:
An attempt was made to call a method that does not exist (com.alibaba.spring.util.BeanUtils.getBeanNames)

The reason is nacos-spring-context 1.1.0 depends on spring-context-support 1.0.11 which isn't compliant with that dubbo depends now.

@zrlw
Copy link
Contributor Author

zrlw commented May 19, 2021

if exclude spring-context-support of dubbo in pom.xml, ClassCastException - java.lang.String cannot be cast to java.lang.Class - will be throwed at DubboAnnotationUtils.java line 95 while creating a bean which has dubbo @reference injections.

@AlbumenJ
Copy link
Member

I think we can remove the dependency of spring-context-support in the future.

@zrlw zrlw changed the title Dubbo 2.7.5, 2.7.9, 2.7.11 are not compliant with nacos-spring-context 1.1.0 Dubbo 2.7.5, 2.7.9, 2.7.11, 2.7.12 are not compliant with nacos-spring-context 1.1.0 Jul 4, 2021
@zrlw zrlw changed the title Dubbo 2.7.5, 2.7.9, 2.7.11, 2.7.12 are not compliant with nacos-spring-context 1.1.0 Dubbo 2.7.5, 2.7.9, 2.7.11, 2.7.12, 3.0, 3.1 are not compliant with nacos-spring-context 1.1.0 Jul 4, 2021
@zrlw zrlw changed the title Dubbo 2.7.5, 2.7.9, 2.7.11, 2.7.12, 3.0, 3.1 are not compliant with nacos-spring-context 1.1.0 Dubbo 2.7.5, 2.7.9, 2.7.11, 2.7.12, 3.0.0, 3.0.1 are not compliant with nacos-spring-context 1.1.0 Jul 4, 2021
@zrlw
Copy link
Contributor Author

zrlw commented Jul 5, 2021

the root cause is alibaba spring-context-support 1.0.11 set default value of two new added elements classValuesAsString and nestedAnnotationsAsMap to true, which destroys dubbo ReferenceAnnotationBeanPostProcessor findFieldAnnotationMetadata and findAnnotatedMethodMetadata functions.

@zrlw
Copy link
Contributor Author

zrlw commented Jul 7, 2021

we make dubbo 2.7.12 and nacos client 1.4.2 working well with each other by #8217 :

  1. change alibaba spring-context-support version of dubbo pom.xml to 1.0.11
  2. set classValuesAsString and nestedAnnotationsAsMap attributes of ReferenceAnnotationBeanPostProcessor to false
    @horizonzy @AlbumenJ

@AlbumenJ
Copy link
Member

AlbumenJ commented Jul 9, 2021

@kylixs PTAL

@zrlw
Copy link
Contributor Author

zrlw commented Jul 13, 2021

related issues:
#7115
#7385

@kylixs
Copy link
Member

kylixs commented Jul 27, 2021

@zrlw Since dubbo 3.0.0, the AbstractAnnotationBeanPostProcessor of alibaba spring-context-support is no longer used, and this problem should not occur, please check it again.
Furthermore, dubbo 3 will gradually remove alibaba spring-context-support.

@kylixs
Copy link
Member

kylixs commented Jul 27, 2021

dubbo 2.7.x has merge pull request: #8217

@kylixs
Copy link
Member

kylixs commented Jul 27, 2021

@zrlw Please add a sample for regression testing:
https://github.com/apache/dubbo-samples/tree/master/dubbo-samples-nacos

@zrlw zrlw changed the title Dubbo 2.7.5, 2.7.9, 2.7.11, 2.7.12, 3.0.0, 3.0.1 are not compliant with nacos-spring-context 1.1.0 Dubbo 2.7.5, 2.7.9, 2.7.11, 2.7.12 are incompatiable with nacos-spring-context 1.1.0 Jul 27, 2021
@zrlw
Copy link
Contributor Author

zrlw commented Jul 27, 2021

@zrlw Since dubbo 3.0.0, the AbstractAnnotationBeanPostProcessor of alibaba spring-context-support is no longer used, and this problem should not occur, please check it again.
Furthermore, dubbo 3 will gradually remove alibaba spring-context-support.

you're right,i didn't notice that dubbo 3.x had used its own AbstractAnnotationBeanPostProcessor.

@zrlw
Copy link
Contributor Author

zrlw commented Jul 27, 2021

@zrlw Please add a sample for regression testing:
https://github.com/apache/dubbo-samples/tree/master/dubbo-samples-nacos

I tried to run Junit Test of dubbo-samples-nacos-configcenter, only got IllegalStateException:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.apache.dubbo.samples.configcenter.DemoServiceIT': Unsatisfied dependency expressed through field 'demoService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'demoService': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: No registry config found or it's not a valid config! The registry config is: <dubbo:registry />

what else should i prepare?
i want to change these codes in NacosUtils.java from

String serverAddr = System.getProperty("nacos.address", "localhost");
Properties properties = new Properties();
properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr);
ConfigService configService = NacosFactory.createConfigService(properties);

to

@Component
public class NacosUtils {	
	@NacosInjected(properties = @NacosProperties(serverAddr = "${nacos.address:localhost}"))
	private ConfigService internalConfigService;
	
	private static ConfigService configService;
	
	@PostConstruct
	public void init() {
		// static field could not be injected directly, so set it here.
		configService = internalConfigService;
	}
        // ...
}

@kylixs
Copy link
Member

kylixs commented Jul 28, 2021

I tried to run Junit Test of dubbo-samples-nacos-configcenter, only got IllegalStateException:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.apache.dubbo.samples.configcenter.DemoServiceIT': Unsatisfied dependency expressed through field 'demoService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'demoService': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: No registry config found or it's not a valid config! The registry config is: <dubbo:registry />

what else should i prepare?

Please start nacos server first

@zrlw
Copy link
Contributor Author

zrlw commented Jul 28, 2021

modified dubbo-samples-nacos-configcenter: apache/dubbo-samples#352

@CrazyHZM CrazyHZM added this to the 2.7.15 milestone Sep 26, 2021
@zrlw zrlw closed this as completed Oct 2, 2021
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

5 participants
@kylixs @AlbumenJ @CrazyHZM @zrlw and others