“为什么管理客户端抛出错误“无法确定本地端口”?”

huangapple go评论67阅读模式
英文:

Why admin client throw the error "couldn't determine local port"?

问题

以下是您提供的内容的翻译:

我已经为每个微服务配置了管理客户端,如下所示。
首先是从pom文件中:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-client</artifactId>
</dependency>

然后是从application.properties文件中:

# 应用程序
spring.application.name=我的示例服务

# Spring Boot管理服务器
spring.boot.admin.client.url=http://localhost:9091
spring.boot.admin.client.enabled=true
spring.boot.admin.client.auto-registration=true
spring.boot.admin.client.username=admin
spring.boot.admin.client.password=password

spring.security.user.name=admin
spring.security.user.password=password
spring.boot.admin.client.instance.metadata.user.name=${spring.security.user.name}
spring.boot.admin.client.instance.metadata.user.password=${spring.security.user.password}

# Actuator端点属性
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always

# 在管理服务器上监视日志文件
logging.file.name=my_sample_service.log
logging.logback.rollingpolicy.max-history=5
logging.logback.rollingpolicy.max-file-size=10MB

在运行mvn install时(构建成功),我收到以下错误消息:

java.lang.IllegalStateException: 无法确定本地端口。 请设置spring.boot.admin.client.instance.service-base-url。
    at de.codecentric.boot.admin.client.registration.DefaultApplicationFactory.getLocalServerPort(DefaultApplicationFactory.java:192) ~[spring-boot-admin-client-2.7.4.jar:2.7.4]
    at de.codecentric.boot.admin.client.registration.DefaultApplicationFactory.getServiceBaseUrl(DefaultApplicationFactory.java:104) ~[spring-boot-admin-client-2.7.4.jar:2.7.4]
    at de.codecentric.boot.admin.client.registration.ServletApplicationFactory.getServiceUrl(ServletApplicationFactory.java:63) ~[spring-boot-admin-client-2.7.4.jar:2.7.4]
    at de.codecentric.boot.admin.client.registration.ServletApplicationFactory.getManagementBaseUrl(ServletApplicationFactory.java:76) ~[spring-boot-admin-client-2.7.4.jar:2.7.4]
    at de.codecentric.boot.admin.client.registration.DefaultApplicationFactory.getHealthUrl(DefaultApplicationFactory.java:154) ~[spring-boot-admin-client-2.7.4.jar:2.7.4]
    at de.codecentric.boot.admin.client.registration.DefaultApplicationFactory.createApplication(DefaultApplicationFactory.java:80) ~[spring-boot-admin-client-2.7.4.jar:2.7.4]
    at de.codecentric.boot.admin.client.registration.DefaultApplicationRegistrator.register(DefaultApplicationRegistrator.java:56) ~[spring-boot-admin-client-2.7.4.jar:2.7.4]
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-5.3.22.jar:5.3.22]

每个客户端应用程序在application.yml中配置了端口:

server:
  port: 9020

我必须说,管理服务器能够正确显示所有客户端的详细信息,这意味着它可以访问所有客户端的执行器URL。但是这个错误很烦人。

英文:

I've configure admin client for each microservice as the following.
First from the pom file:

 &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
        &lt;/dependency&gt;     
        &lt;dependency&gt;
            &lt;groupId&gt;de.codecentric&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-admin-starter-client&lt;/artifactId&gt;          
        &lt;/dependency&gt;

Then from the application.properties file:

# Application
spring.application.name=My Sample Service

# Spring boot admin server 
spring.boot.admin.client.url=http://localhost:9091
spring.boot.admin.client.enabled=true
spring.boot.admin.client.auto-registration=true
spring.boot.admin.client.username=admin
spring.boot.admin.client.password=password

spring.security.user.name=admin
spring.security.user.password=password
spring.boot.admin.client.instance.metadata.user.name=${spring.security.user.name}
spring.boot.admin.client.instance.metadata.user.password=${spring.security.user.password}


# Actuator endpoints properties
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=always

# To monitor log file on admin server
logging.file.name=my_ssample_service.log
logging.logback.rollingpolicy.max-history=5
logging.logback.rollingpolicy.max-file-size=10MB

When running mvn install (the build is successful) I get the following error:

java.lang.IllegalStateException: couldn&#39;t determine local port. Please set spring.boot.admin.client.instance.service-base-url.
	at de.codecentric.boot.admin.client.registration.DefaultApplicationFactory.getLocalServerPort(DefaultApplicationFactory.java:192) ~[spring-boot-admin-client-2.7.4.jar:2.7.4]
	at de.codecentric.boot.admin.client.registration.DefaultApplicationFactory.getServiceBaseUrl(DefaultApplicationFactory.java:104) ~[spring-boot-admin-client-2.7.4.jar:2.7.4]
	at de.codecentric.boot.admin.client.registration.ServletApplicationFactory.getServiceUrl(ServletApplicationFactory.java:63) ~[spring-boot-admin-client-2.7.4.jar:2.7.4]
	at de.codecentric.boot.admin.client.registration.ServletApplicationFactory.getManagementBaseUrl(ServletApplicationFactory.java:76) ~[spring-boot-admin-client-2.7.4.jar:2.7.4]
	at de.codecentric.boot.admin.client.registration.DefaultApplicationFactory.getHealthUrl(DefaultApplicationFactory.java:154) ~[spring-boot-admin-client-2.7.4.jar:2.7.4]
	at de.codecentric.boot.admin.client.registration.DefaultApplicationFactory.createApplication(DefaultApplicationFactory.java:80) ~[spring-boot-admin-client-2.7.4.jar:2.7.4]
	at de.codecentric.boot.admin.client.registration.DefaultApplicationRegistrator.register(DefaultApplicationRegistrator.java:56) ~[spring-boot-admin-client-2.7.4.jar:2.7.4]
	at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-5.3.22.jar:5.3.22]

Each client application has port configured in application.yml

server:
  port : 9020

I must say that the admin server is able to show all the clients' details correctly which means it has access to all clients actuator urls. But the error is annoying.

答案1

得分: 0

Adding the following spring boot property for each microservice client solve
the build error problem:

spring.boot.admin.client.instance.service-base-url=http://localhost:9020

Where 9020 is the port of the admin client (not server). Also it appears that this
property is being used by spring test when building with mvn install.

Now all builds works with no errors. hope it helps someone who has similar issue.

英文:

Adding the following spring boot property for each microservice client solve
the build error problem:

spring.boot.admin.client.instance.service-base-url=http://localhost:9020

Where 9020 is the port of the admin client (not server). Also it appears that this
property is being used by spring test when building with mvn install.

Now all builds works with no errors. hope it helps someone who has similar issue.

huangapple
  • 本文由 发表于 2023年5月14日 18:18:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76246935.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定