Spring启动与Eureka服务器

时间:2017-12-24 08:37:49

标签: spring-boot cloud spring-cloud netflix-eureka

我已经构建了一个应用程序,它是一个Eureka服务器,服务注册表。
pom.xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>Microservice</groupId>
    <artifactId>Micro1</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.8.RELEASE</version>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
            <version>1.0.0.RELEASE</version>
        </dependency>
        <!-- This is a web application -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- Tomcat embedded container-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

并且运行该应用程序的主类如下:

package org.eureka.server;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class EurekaServiceApplication {

    public static void main(String[] args) {
        //ApplicationContext ctx = new SpringApplicationBuilder().bannerMode(Banner.Mode.CONSOLE).run(args);
        SpringApplication.run(EurekaServiceApplication.class, args);
    }
}

application.yml就是这样:

server:
  port: 8761

当它由clean spring-boot:run命令运行时,会引发以下异常:

  

引起:java.lang.NoSuchMethodError:   org.springframework.boot.builder.SpringApplicationBuilder.showBanner(Z)Lorg / springframework的/引导/助洗剂/ SpringApplicationBuilder;     在   org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:110)     在   org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:75)     在   org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:1)     在   org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)     在   org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)     在   org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)     在   org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)     在   org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)     在   org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)     在   org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:325)     在   org.springframework.boot.SpringApplication.run(SpringApplication.java:296)     在   org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)     在   org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)     在   org.eureka.server.EurekaServiceApplication.main(EurekaServiceApplication.java:16)

     

... 6更多[INFO]

当我删除pom.xml中的eureka依赖项时,应用程序运行成功 哪里错了?

1 个答案:

答案 0 :(得分:1)

你会像这样改变你的pom

context.sendBroadcast(receiver);