Spring Boot Admin无法修改Spring Boot应用运行时日志级别求助
问题排查与修复方案
1. 配置Spring Boot Admin客户端的管理端点路径
你的应用将管理端点的base-path设为了/monitor,但Spring Boot Admin服务端默认会以/actuator作为客户端的端点前缀,导致调用日志级别修改接口时路径错误。需要在客户端的metadata中添加management.context-path配置:
修改application.yml中的spring.boot.admin.client.instance.metadata部分:
spring: boot: admin: client: url: http://localhost:8080 username: admin password: admin instance: metadata: user: name: ${spring.security.user.name} password: ${spring.security.user.password} management: context-path: ${management.endpoints.web.base-path}
2. 显式启用Loggers端点
虽然默认endpoints.enabled-by-default: true会启用Loggers端点,但显式配置可避免潜在的配置覆盖问题,在management节点下添加:
management: endpoint: loggers: enabled: true
3. 关闭管理端点的CSRF保护
Spring Security默认启用CSRF保护,而Spring Boot Admin调用客户端的POST接口(修改日志级别为POST请求)时未携带CSRF令牌,会导致请求被拦截。针对管理端点关闭CSRF检查:
修改WebSecurityConfig.java的configure(HttpSecurity http)方法:
protected void configure(HttpSecurity http) throws Exception { http .csrf(csrf -> csrf.ignoringAntMatchers("/monitor/**")) .authorizeRequests() .antMatchers("/", "/swagger-ui.html", "/swagger-ui/**", "/openapi/**", "/openapi.yaml").permitAll() .antMatchers("/actuator/**").permitAll() .antMatchers("/variables.css").permitAll() .antMatchers("/monitor/**", "/api/**").permitAll() .antMatchers("/example/**").permitAll() .anyRequest().authenticated() .and() .formLogin() .and() .logout(); }
4. 验证端点可用性
重启客户端应用后,直接访问http://<客户端地址>:<端口>/monitor/loggers,确认能返回JSON格式的日志配置信息,说明端点正常暴露。
完成以上配置后,重新在Spring Boot Admin面板尝试修改日志级别即可生效。
内容的提问来源于stack exchange,提问作者jka_dk
相关产品推荐
相关产品推荐

