Spring Boot Client无法向管理员注册 [英] Spring Boot Client Failed to register with Admin
问题描述
我有一台运行良好的Spring Boot Admin服务器.这些是文件:
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);
}
}
这很好.我可以导航到http://localhost:9090/#/applications
并看到管理服务器就可以了.
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
启动客户端应用程序时,可以导航到http://localhost:8081/actuator/health
并查看所有运行状况信息.但是我最终也会在控制台中遇到这些错误:
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
我在做什么错了?
推荐答案
基本上,由于Spring Boot Admin Server(2.1.0)和Client(1.5.7)版本的不同,它无法注册.
Basically it failing to register because of difference in version of Spring Boot Admin Server(2.1.0) and Client(1.5.7).
客户端1.5.7使用url//server:port/api/applications命中服务器,但是服务器2.1.0预期在//server:port/instances路径处注册,因此只需要更新客户端以命中预期的服务器路径
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.
只需在调试日志中启动服务器/客户端,即可获得有关其尝试访问的URL的更多提示.
Just start the server/client in debug logs to get more hint on what url it trying to hit.
此处要指出的一点是,由于许多端点的版本不兼容,我们将无法获得所有信息.执行器模块在1.X和2.X之间完全更改.
基于以上几点,以下是解决此问题的方法:
With above point, below is workaround to get this done with limitations :
客户端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上看到.
Its working for me with limitations like not able to see metrics etc. but still handfull of information visible on Admin Server.
这篇关于Spring Boot Client无法向管理员注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!