SpringBoot adds context path to Actuator endpoints
Asked Answered
T

2

6

I am running my springboot application by setting context-path to /myservice. This results into appending all my actuator endpoints exposed at the URL- http://localhost:8080/myservice/actuator/, while I want only http://localhost:8080/actuator/. Is there a way to tell the springboot to ignore appending context path to actuator endpoints (through DispatcherServlet or CXFServlet or anything) Please help.

Tinderbox answered 21/5, 2021 at 15:53 Comment(0)
P
7

Unfortunately this is not possible.

From the documentation:

Unless the management port has been configured to expose endpoints by using a different HTTP port, management.endpoints.web.base-path is relative to server.servlet.context-path (Servlet web applications) or spring.webflux.base-path (reactive web applications). If management.server.port is configured, management.endpoints.web.base-path is relative to management.server.base-path.

Source: https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#actuator.monitoring.customizing-management-server-context-path

What you could do is to use a different port for the management endpoints.

management.server.port=8081

Then you will get http://localhost:8081/actuator

Pamilapammi answered 21/5, 2021 at 15:59 Comment(0)
K
3

Technically it is not possible because spring boot has only one DispatcherServlet which is a front controller, if you want two different paths then you can use @RequestMapping annotation on two different controllers`

Still of you want two different context-paths then you should have two DispatcherServlet's

Kareenkarel answered 21/5, 2021 at 16:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.