Spring Boot Jersey and Monitoring URL's

萝らか妹 提交于 2019-12-13 01:06:32

问题


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:


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).



来源:https://stackoverflow.com/questions/26941817/spring-boot-jersey-and-monitoring-urls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!