配置 Spring Boot Admin报错。
2022-01-25 15:47:40.025 WARN 12808 --- [gistrationTask1] d.c.b.a.c.r.ApplicationRegistrator : Failed to register application as Application(name=spring-boot-application, managementUrl=http://192.168.1.1:8080/actuator, healthUrl=http://192.168.1.1:8080/actuator/health, serviceUrl=http://192.168.1.1:8080/) at spring-boot-admin ([http://localhost:8081/instances]): I/O error on POST request for "http://localhost:8081/instances": Connect to localhost:8081 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect; nested exception is org.apache.http.conn.HttpHostConnectException: Connect to localhost:8081 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect. Further attempts are logged on DEBUG level
2022-01-25 15:47:40.025 WARN 12808 — [gistrationTask1] d.c.b.a.c.r.ApplicationRegistrator : Failed to register application as Application(name=spring-boot-application, managementUrl=http://192.168.1.1:8080/actuator, healthUrl=http://192.168.1.1:8080/actuator/health, serviceUrl=http://192.168.1.1:8080/) at spring-boot-admin ([http://localhost:8081/instances]): I/O error on POST request for “http://localhost:8081/instances”: Connect to localhost:8081 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect; nested exception is org.apache.http.conn.HttpHostConnectException: Connect to localhost:8081 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect. Further attempts are logged on DEBUG level
我的actuator用的8080端口,http://localhost:8080/actuator
admin的配置项用的8081
spring.boot.admin.client.url=http://localhost:8081
这个配置项的官方说明是:
通过配置 Spring Boot Admin Server 的 URL 来启用 SBA Client:(SBA是Spring Boot Admin)
要注册的 Spring Boot 管理服务器的 URL
我的理解是这个admin server的url就是actuator的url,
所以,把actuator的url放到这里就OK了。
spring.boot.admin.client.url=http://localhost:8080
另外,如果client端的url如果不想用主机名(http://rye-honor:8080/applications)。
那就加一下这个配置。
spring.boot.admin.client.instance.service-host-type=ip
如果你的admin依赖导入的版本比较老,找不到上面这个配置项,
就找一下有没有这个配置项。
spring.boot.admin.client.instance.prefer-ip=true
把这个设置为true就可以了。
进入源码可以看到。
/**
* Should the registered urls be built with server.address or with hostname.
* @deprecated Use serviceHostType instead.
*/
@Deprecated
private boolean preferIp = false;
新版本用“serviceHostType”替代。
但是这个配置在最新版本不会影响启动。所以配不配置都可以。
另外,记得配置这个。
management.endpoints.web.exposure.include=*
项目启动成功之后浏览器访问localhost:8080就可以了。