我已经创建了一个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 /”开头的其他API工作正常 那么有没有办法为其余API和执行器端点设置相同的基本路径?
答案 0 :(得分:0)
找到解决方案:
endpoints.health.enabled=true
server.servlet.path=/api
management.endpoints.web.base-path=/v1
management.endpoints.web.path-mapping.health=health