Actuator with Spring boot Jersey

旧时模样 提交于 2019-12-11 04:59:19

问题


I'm using Jersey starter in my web application.

org.springframework.boot spring-boot-starter-jersey 1.4.2.RELEASE

Trying to integrate the Actuator endpoints into my application.Used the following maven dependency

org.springframework.boot spring-boot-starter-actuator 1.5.2.RELEASE org.springframework.boot spring-boot-starter-web 1.5.2.RELEASE

When I access the health endpoint, it was giving me 404 error. http://localhost:8080/context/health

Do I need to add any other configuration class to my application that will initialize the actuator? Can anyone point me in the correct direction?


回答1:


Most likely you are using /* (default if not specified) for the Jersey mapping. The problem is that Jersey will get all the request. It does not know that it needs to forward to any actuator endpoints.

The solutions are described in this post. Either change the mapping for Jersey, or change Jersey to be used as filter instead of a servlet. Then set the Jersey property to forward requests for URLs it doesn't know.




回答2:


This is how i was able to ti get this working

Step 1 By default Jersey will be set up resource configured by extends ResourceConfig as serverlate. We need to tell spring boot to use it as filter. Set it as using below property

spring .jersey.type: filter 

Step 2

I was using below configuration for registering resources

   @component 
    public class MyResourceConfig extends ResourceConfig  {

        public MyResourceConfig () {
            try {
                register(XXX.class);

            } catch (Exception e) {
                LOGGER.error("Exception: ", e);                   
            }
        }       

    } 

Change @component to @Configuration and also add below property property(ServletProperties.FILTER_FORWARD_ON_404, true);

Final Configuration

@Configuration 
        public class LimitResourceConfig extends ResourceConfig  {

            public LimitResourceConfig() {
                try {
                    register(XXX.class);
                    property(ServletProperties.FILTER_FORWARD_ON_404, true);

                } catch (Exception e) {
                    LOGGER.error("Exception: ", e);                   
                }
            }       

        } 


来源:https://stackoverflow.com/questions/43371344/actuator-with-spring-boot-jersey

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