我创建了一个 Spring Boot 应用程序,它有 ServletRegistrationBean:
@Bean
public ServletRegistrationBean<DispatcherServlet> restApi() {
final DispatcherServlet dispatcherServlet = new DispatcherServlet(webApplicationContext);
final ServletRegistrationBean<DispatcherServlet> servletRegistrationBean = new ServletRegistrationBean<>(dispatcherServlet, "/api/*");
servletRegistrationBean.setName(DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME);
return servletRegistrationBean;
}
我想将执行器的基本路径设置为“/api”:
management.endpoints.web.base-path=/api
management.endpoint.health.enabled=true
management.endpoints.enabled-by-default=false
management.endpoints.web.path-mapping.health=/v1/health
但这不起作用。对于任何其他基本路径,它都能正常工作 {{localhost}}/api GET 返回端点列表,但{{localhost}}/api/v1/health GET 返回 404
我的其他以“/api/v1/”开头的rest API工作正常那么有没有办法为rest API和Actuator端点设置相同的基本路径?