Spring Boot Jersey and Monitoring URL's

2.7k views Asked by At

We have a simple Spring Boot application with Jersey.

Spring Boot provides default monitoring end points

http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#production-ready-monitoring

Example:

@Component
public class JerseyConfig extends ResourceConfig {

    public JerseyConfig() {
        // registering resources from rest package
        packages("com.xyx.abc.rest");

    }

}

The REST end points that are provided by Spring Boot are not available in the context of a Spring Boot Jersey Application.

The Spring Boot dependency includes Jersey, starter-actuator, starter-tomcat.

Our REST resources show up fine, but the ones provided by Spring Boot for monitoring dont show up.

E.g http://abc.xyx.com:8080/health returns a 404

1

There are 1 answers

6
Dave Syer On BEST ANSWER

If you are using it as a Filter you need to tell Jersey not to handle those requests. E.g. by putting the Jersey resources under a separate path, like "/api/*" or something:

@Bean
public FilterRegistrationBean jersey() {
    FilterRegistrationBean bean = new FilterRegistrationBean();
    ...
    bean.setUrlPatterns(Lists.newArrayList("/api/*"));
    return bean;
}

(from here).

Or by declaring that your admin endpoints are "static" (via another init parameter "com.sun.jersey.config.property.WebPageContentRegex"):

@Bean
public FilterRegistrationBean jersey() {
    FilterRegistrationBean bean = new FilterRegistrationBean();
    ...
    bean.addInitParameter("com.sun.jersey.config.property.WebPageContentRegex",
            "/admin/.*");
    return bean;
}

where we have set management.contextPath=/admin in the Spring Boot external configuration (otherwise you'd have to enumerate all the endpoints in the regex).

You can also tell Jersey to ignore unresolved requests (instead of sending a 404). That would also achieve your goal, but might affect your client apps (if they rely on a 404 for their behaviour).