我正在使用 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
问题
您知道为什么应用程序没有被注册吗?是因为您不能在同一个应用程序中拥有 spring-boot-admin-starter-server
和 spring-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 错误,但应用程序控制台报告服务器已关闭:
控制台日志:没有错误
http://localhost:8085/actuator/health {"status":"UP"}
但是,详细信息显示存在 401。
最佳答案
我通过将 /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/