【发布时间】:2020-10-26 15:50:59
【问题描述】:
我正在配置 spring Boot 执行器,但 /actuator 和 /health 端点在每个 GET 请求中返回 405。
我打开了整个安全机制,但它不起作用:
management.endpoints.jmx.exposure.exclude=*
management.endpoints.web.exposure.include=health,info,beans,env
management.endpoint.health.enabled=true
management.security.enabled=false
management.endpoint.beans.cache.time-to-live=10s
management.endpoints.web.cors.allowed-origins=*
management.endpoints.web.cors.allowed-methods=GET,POST
我添加了以下配置
@Configuration(proxyBeanMethods = false)
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/health", "/actuator").permitAll().and().csrf().disable();
super.configure(http);
}
}
所以,我按照教程进行操作,看起来很简单,我不明白为什么我会在默认 GET 请求中得到这个 405。当我用 cURL 调用端点时:
curl http://localhost:8080/sm-integration/health -v --> 405
curl -X POST http://localhost:8080/sm-integration/health -v --> 400
我在执行 POST 时不理解 400 Bad Request。文档指出 /health 是最基本和开放的端点,应该被称为 GET 调用。那么为什么是 405?
更新 在收到几个答案后,我设置了这样的配置:
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/health", "/actuator/**").permitAll().and().csrf().disable();
}
我将调用更改为 http://localhost:8080/sm-integration/actuator/health
但我仍然得到 405。
在 Tomcat 访问日志中,我确实看到请求已经到达。
10.0.2.2 - - [06/Jul/2020:16:41:06 +0000] "GET /sm-integration/actuator/health HTTP/1.1" 405 5
10.0.2.2 - - [06/Jul/2020:16:41:12 +0000] "GET /sm-integration/actuator/health HTTP/1.1" 405 5
10.0.2.2 - - [06/Jul/2020:16:41:45 +0000] "GET /sm-integration/actuator/health HTTP/1.1" 405 5
10.0.2.2 - - [06/Jul/2020:16:42:18 +0000] "GET /sm-integration/actuator/health HTTP/1.1" 405 5
10.0.2.2 - - [06/Jul/2020:16:43:04 +0000] "GET /sm-integration/actuator HTTP/1.1" 405 5
【问题讨论】:
-
除非您将执行器端点移动到
/,否则/health是错误的路径。应该是/actuator/health。 -
谢谢,我也尝试使用 /actuator 前缀,得到同样的错误
标签: java spring spring-boot spring-security spring-boot-actuator