0

我创建了一个 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端点设置相同的基本路径?

4

1 回答 1

0

找到了解决办法:

endpoints.health.enabled=true
server.servlet.path=/api
management.endpoints.web.base-path=/v1
management.endpoints.web.path-mapping.health=health
于 2019-07-19T15:03:08.753 回答