This one took me a few hours to find an easy solution for, so I thought I’d share here so it may help others.
I have been working to create a Jersey web service that will run in a Spring Boot instance, and wanted to make use of the nifty actuator endpoints that are available in Spring Boot for things such as monitoring the health of the application, listing the beans in use by the application, and shutting down the application, among other things which are detailed on the Spring Boot website
The problem is that Jersey application will take over all URLS at the root, thus masking the Spring Boot URLs such as /health, even though the application itself is not using that mapping.
The easiest solution I found was to add an application path to the Jersey application so that it listened for requests arriving from a different URL root such as /api/MyJerseyService, where /api is the root that Jersey will use.
Configuring this was relatively straightforward and only required an additional annotation in the AppConfig class. Notice the @ApplicationPath(“/api”) annotation, specifying that Jersey should use /api as the application root.
@Configuration
@ApplicationPath("/api")
public class AppConfig extends ResourceConfig {
public AppConfig() {
register( UvDataResource.class );
}
}
Notice the @ApplicationPath(“/api”) which will tells the application to use /api as the root. Now when the Spring Boot health web service is invoked at the following URL, the expected results are returned.
{
"status": "UP",
"diskSpace": {
"status": "UP",
"free": 118162386944,
"threshold": 10485760
}
}
While the call to the Jersey Webservice produces the expected result:
http://localhost:8080/api/uvdata/AMLOPS_EQUIP_MASTER/844024
{
"id": "844024",
"equipmentType": "11*3",
"serialNumber": "844024",
"checksum": 750288259,
"badValuesMap": {},
"multiValueMap": {}
}
twitter: @RobTerpilowski
Great post! Help me a lot.
Thanks
Good one. I was struggling why the spring actuator endpoints were not accessible. This post helped to resolve the issue. Thanks!
Great! I’m glad that it helped.
Hey! Have you tried to tweek application.properties ?
server.port=8000
server.context-path=/api
management.port=9000