spring-boot-admin - Spring Boot 管理服务器和客户端位于同一应用程序中

标签 spring-boot-admin

我正在使用 Spring Boot 2.5.1 和 Java 11。

我试图在同一个应用程序中创建SpringBoot 管理服务器客户端,但是当我启动它时,我在控制台中收到以下错误。

引用号:https://github.com/codecentric/spring-boot-admin

错误

Failed to register application as Application(name=PowWow, managementUrl=http://localhost:8085/actuator, healthUrl=http://localhost:8085/actuator/health, serviceUrl=http://localhost:8085/) at spring-boot-admin ([http://localhost:8085/instances]): 401 : [no body]. Further attempts are logged on DEBUG level

我在 Spring Boot 应用程序中有以下代码:

pom.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5.1</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

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

application.properties

server.port=8085
spring.application.name=PowWow
logging.file.name=powwow-logfile.log
logging.logback.rollingpolicy.max-history=3
logging.logback.rollingpolicy.max-file-size=5MB
spring.boot.admin.client.url=http://localhost:8085
management.endpoints.web.exposure.include=*
management.endpoints.health.show-details=always

PowWowApplication.java

@SpringBootApplication
@EnableScheduling
@EnableAdminServer
public class PowWowApplication {

更多信息

我可以访问以下网址,但它不会加载应用程序:http://localhost:8085/applications

enter image description here

问题

您知道为什么应用程序没有被注册吗?是因为您不能在同一个应用程序中拥有 spring-boot-admin-starter-serverspring-boot-admin-starter-client 吗?

更多信息

我意识到 application.properties 有:

web.access.username=user
web.access.password=password

所以我还添加以下内容以允许客户端访问:

spring.boot.admin.client.username=user
spring.boot.admin.client.password=password

这消除了上述错误,即启动服务器时不再出现 401 错误,但应用程序控制台报告服务器已关闭:

enter image description here

控制台日志:没有错误

http://localhost:8085/actuator/health {"status":"UP"}

但是,详细信息显示存在 401。

enter image description here

最佳答案

我通过将 /actuator/** 添加到以下内容解决了此问题:

public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
       
        http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
                .authorizeRequests().antMatchers("/soapWS/**").permitAll().and()
                .authorizeRequests().antMatchers("/actuator/**").permitAll()
                .anyRequest().authenticated().and()
                .httpBasic().and()
                .csrf().disable();
    }

关于spring-boot-admin - Spring Boot 管理服务器和客户端位于同一应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70667786/

相关文章:

spring-boot - Spring boot admin 列出 kubernetes 内部 url。无法导航到应用程序页面

openshift - Spring Cloud Kubernetes 使用自定义 spring.servlet.context-path 获取 url

java - 从spring-boot-admin-server 1.4.6升级到1.5.2后的RestClientException

java - Spring Boot REST API 的指标收集

java - 添加 spring-boot-admin-starter-client 依赖项后无法解析占位符

spring - 在 Spring Boot 管理员中未经授权

java - 为什么Spring Cloud @EnableSidecar使用@EnableCircuitBreaker

java - Spring 启动身份验证 - 管理控制台 403 响应客户端

spring-boot - Ehcache 3 和 Spring Boot Admin 统计信息

Spring Cloud Stream 和 RabbitMQ 健康检查