In spring boot app I set e.g. server.context-path=/mymodule
. This is convenient because I don't need to repeat over and over again /mymodule
prefix in @RequestMapping
.
Further I want to have actuator endpoints grouped together on URLs with common prefix so I set management.context-path=/actuator
.
Now actuator endpoint are mapped to /mymodule/actuator
.
From security perspective I want to have actuator endpoints mapped to /actuator
. Simple config on reverse proxy https://mydomain/api/mymodule -> http://oneofmyserver:port/mymodule
protects that end users would not be able to access actuator.
Is it possible to map actuator endpoints to /actuator
?
Just like many other configuration options, the context path in Spring Boot can be changed by setting a property, server. servlet. context-path. Note that this works for Spring Boot 2.
By default base-path of actuator endpoints is /actuator , we can change it to any other value by setting management. endpoints. web. base-path in application properties file.
To enable Spring Boot actuator endpoints to your Spring Boot application, we need to add the Spring Boot Starter actuator dependency in our build configuration file. Maven users can add the below dependency in your pom. xml file. Gradle users can add the below dependency in your build.
In order to have multiple context paths, you're limited to deploying the application multiple times with that convenient property set to what you want for each deployment. However, this is resource expensive because you're spinning up two applications for every one application you would normally spin up.
Probably better solution from security perspective is to export actuator on totally different port. To do it just add such properties:
management.port=9080
You can also just change context-path of actuator endpoints by using
management.context-path=/actuator
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With