似乎 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)

有什么建议吗?