I am building a Spring Cloud Config server and I use the property server.contextPath: /configServer
but I also want my server to respond with 200 on any request to /ping
(not /configServer/ping
).
Is there any way to bypass the contextPath property for a specific RestController (or any other way to achieve that)?
Thanks.
Maybe add a ServletRegistrationBean. This would allow you to listen for requests coming to
/ping
or for/*
.I found the solution to my problem:
There is the spring property
spring.cloud.config.server.prefix
which does exactly what I was looking for. This prefix is like contextPath but only for the configuration server hence I can write my custom controller for/ping
mapping while configuration server serves all request to/configServer
.UPDATE:
sample code:
This is the controller to respond to /ping
in the application properties (i use yml):
I cannot share the whole config file but it worths mentioning it doesn't include the
server.contextPath
property.This will result in these mappings:
My pom.xml
Hope that helps.