Spring Boot Client无法向管理员注册

时间:2018-11-15 13:47:09

标签: java spring spring-boot spring-boot-admin

我有一台运行良好的Spring Boot Admin服务器。这些是文件:

pom.xml

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

<dependencies>
    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-server</artifactId>
    </dependency>
    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-server-ui</artifactId>
    </dependency>
      <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-test</artifactId>
          <scope>test</scope>
      </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-dependencies</artifactId>
            <version>${spring-boot-admin.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

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

application.properties

server.port = 9090
spring.application.name = adminserver

DemoApplication.java

@SpringBootApplication
@EnableAdminServer
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

这很好。我可以导航到http://localhost:9090/#/applications并查看管理服务器。 enter image description here

问题是当我尝试将我的一个客户端应用程序注册到服务器时。这是我的客户端应用程序的详细信息:

pom.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.0.RC1</version>
    <relativePath/>
</parent>

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

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-hateoas</artifactId>
    </dependency>
    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-starter-client</artifactId>
        <version>1.5.7</version>
    </dependency>
</dependencies>

application.yml

spring:
  profiles: default
  boot:
    admin:
      url: http://localhost:9090
management:
  context-path: /actuator

启动客户端应用程序时,我可以导航至http://localhost:8081/actuator/health并查看所有运行状况信息。但是我也最终在控制台中得到了这些错误:

DEBUG --- [   registrationTask1] de.codecentric.boot.admin.client.registration.ApplicationRegistrator                       : Failed to register application as Application [name=ClientApp, managementUrl=http://richard-desktop:8081/actuator/, healthUrl=http://richard-desktop:8081/actuator/health/, serviceUrl=http://richard-desktop:8081/] at spring-boot-admin ([http://localhost:9090/api/applications]): 404 Not Found 
DEBUG --- [   registrationTask1] de.codecentric.boot.admin.client.registration.ApplicationRegistrator                       : Failed to register application as Application [name=ClientApp, managementUrl=http://richard-desktop:8081/actuator/, healthUrl=http://richard-desktop:8081/actuator/health/, serviceUrl=http://richard-desktop:8081/] at spring-boot-admin ([http://localhost:9090/api/applications]): 404 Not Found 
DEBUG --- [   registrationTask1] de.codecentric.boot.admin.client.registration.ApplicationRegistrator                       : Failed to register application as Application [name=ClientApp, managementUrl=http://richard-desktop:8081/actuator/, healthUrl=http://richard-desktop:8081/actuator/health/, serviceUrl=http://richard-desktop:8081/] at spring-boot-admin ([http://localhost:9090/api/applications]): 404 Not Found 

我在这里做什么错了?

1 个答案:

答案 0 :(得分:2)

基本上,由于Spring Boot Admin Server(2.1.0)和Client(1.5.7)版本的不同,它无法注册。

客户端1.5.7使用url // server:port / api / applications命中服务器,但是服务器2.1.0预期在// server:port / instances路径处注册,因此只需更新客户端以命中预期的服务器路径

只需在调试日志中启动服务器/客户端,即可获得有关其尝试访问的URL的更多提示。

此处要指出的一点是,由于许多端点的版本不兼容,我们将无法获得所有信息。执行器模块在1.X和2.X之间完全更改。

基于以上几点,以下是解决此问题的解决方法:

客户端Java文件:

@SpringBootApplication
public class ClientApplication {

    public static void main(String[] args) {
        SpringApplication.run(ClientApplication.class, args);
    }
}

客户端属性文件:

server.port=8081
spring.boot.admin.url=http://localhost:8080
spring.boot.admin.api-path=/instances
management.security.enabled=false

它为我工作时有一些局限性,例如无法查看指标等,但仍然有少量信息可以在Admin Server上看到。