3

我正在尝试在 SpringCloud 的帮助下向领事注册一个示例 SpringBoot 服务,但在使用最新版本时没有成功。

成功的版本:

  • SpringBoot:2.0.0.RELEASE
  • 云:Finchley.RELEASE
  • 领事:1.4.0

没有成功的版本:

  • SpringBoot:2.1.1.RELEASE
  • 云:Finchley.RELEASE
  • 领事:1.4.0

我的pom:

<?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>
    <artifactId>server</artifactId>
    <groupId>com.ote.test</groupId>
    <version>1.0-SNAPSHOT</version>

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

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-parent</artifactId>
                <!--version>2.0.0.RELEASE</version-->                    
                <version>2.1.1.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Finchley.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-consul-discovery</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <compilerVersion>${java.version}</compilerVersion>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

我用以下命令启动领事: consul agent -dev

我的服务提供“/health”端点并声明@EnableDiscoveryClient

我的配置是(application.yml 或 bootstrap.yml,结果相同):

spring:
  application:
    name: server
  cloud:
    consul:
      host: localhost
      port: 8500
      discovery:
        tags: test
        enabled: true
        instanceId: ${spring.application.name}:${vcap.application.instance_id:${spring.application.instance_id:${random.value}}}
        healthCheckPath: /health
        healthCheckInterval: 5s

当我使用 SpringBoot 2.0.0.RELEASE 启动服务时,它运行良好。当我使用 SpringBoot 2.1.1.RELEASE 启动完全相同的服务时,该服务未注册到 consul(并且无法被任何客户端发现)

有什么问题或遗漏?

4

0 回答 0