Spring Boot Client Failed to register with Admin

半腔热情 提交于 2019-12-24 06:44:34

问题


I have an Spring Boot Admin server running just fine. Here are the files:

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);
    }
}

This works great. I can navigate to http://localhost:9090/#/applications and see the admin server just fine.

The problem is when I try to register one of my client applications to the server. Here are the details for my client application:

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

When I start up the client application, I can navigate to http://localhost:8081/actuator/health and see all the health info just fine. But I also end up getting these errors in the console:

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 

What am I doing wrong here?


回答1:


Basically it failing to register because of difference in version of Spring Boot Admin Server(2.1.0) and Client(1.5.7).

Client 1.5.7 hits at server with url //server:port/api/applications but server 2.1.0 expected registration at //server:port/instances path so just need to update the client to hit the expected server path.

Just start the server/client in debug logs to get more hint on what url it trying to hit.

Point to be noted here that We wont be getting all information due version uncompatability for many endpoints. Actuator module completely changed between 1.X and 2.X.

With above point, below is workaround to get this done with limitations :

Client Java file :

@SpringBootApplication
public class ClientApplication {

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

Client Property file :

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

Its working for me with limitations like not able to see metrics etc. but still handfull of information visible on Admin Server.



来源:https://stackoverflow.com/questions/53320887/spring-boot-client-failed-to-register-with-admin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!