spring-cloud-consul与spring-boot-2.0.0.M1不兼容

时间:2017-06-09 05:56:33

标签: spring-boot spring-cloud spring-cloud-consul

目前发布的 spring-cloud-consul (此时 1.2.2-snapshot )与 spring-boot不兼容-2.0.0.M1 即可。

作为微服务的新成员,我试图将consul集成到我的项目中以支持服务注册表,但是在将consul starter插入pom.xml之后项目无法启动。

好的,这里是示例代码:

//DemoApplication.java
@SpringBootApplication
@EnableDiscoveryClient
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

//pom.xml
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.4.RELEASE</version>  <!-- evertything works fine -->
    <!--<version>2.0.0.M1</version>--> <!-- project fail to start -->
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-consul-all</artifactId>
        </dependency>
    </dependencies>

....some other irrelevant configs

//application.properties
spring.cloud.consul.port = 8500
spring.cloud.consul.host = localhost

如上面的代码所示,如​​果使用 spring-boot-1.5.4.RELEASE ,一切正常,而使用 spring-boot-2.0.0.M1则无法启动项目,抱怨如下:

13:52:15.444 [main] ERROR org.springframework.boot.SpringApplication - Application startup failed
java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.<init>([Ljava/lang/Object;)V
    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:157)
    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:98)
    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:64)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:72)
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:360)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:328)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1278)
    at com.cmcc.syw.demo.DemoApplication.main(DemoApplication.java:11)

有关原因的任何建议吗?

0 个答案:

没有答案