nacos版本与Springboot兼容问题
环境:
spring-boot版本号:1.5.9
spring-cloud版本号:Edgware.SR1
spring cloud alibaba版本号:0.1.2RELEASE
启动的时候出现了如下错误:
org.springframework.beans.factory.BeanCreationException:Error creating bean with name 'nacosAutoServiceRegistration' defined in classpath resource[org/springframework/cloud/alibaba/nacos/NacosDiscoveryAutoConfiguration.class]:Bean instantiation via factory method failed; nested exception isorg.springframework.beans.BeanInstantiationException: Failed to instantiate[org.springframework.cloud.alibaba.nacos.registry.NacosAutoServiceRegistration]:Factory method 'nacosAutoServiceRegistration' threw exception; nested exceptionis java.lang.NoSuchMethodError:org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.(Lorg/springframework/cloud/client/serviceregistry/ServiceRegistry;Lorg/springframework/cloud/client/serviceregistry/AutoServiceRegistrationProperties;)V
错误原因:
NacosAutoServiceRegistration继承AbstractAutoServiceRegistration,在spring-cloud-commons:1.3.1RELEASE中,构造函数只有一个参数故出现上述错误
解决方案:
将spring-cloud-commons的版本升级为1.3.5RELEASE,在pom文件中引入以下代码:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
<version>1.3.5.RELEASE</version>
</dependency>