带弹簧靴泽西的执行器

时间:2017-04-12 13:44:05

标签: java jersey spring-boot-actuator

我在我的网络应用程序中使用Jersey启动器。

  

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

尝试将Actuator端点集成到我的应用程序中。使用以下maven依赖

  

org.springframework.boot         弹簧引导起动致动器         1.5.2.RELEASE         org.springframework.boot         弹簧引导启动的Web         1.5.2.RELEASE

当我访问健康端点时,它给了我404错误。 http://localhost:8080/context/health

我是否需要在我的应用程序中添加任何其他配置类来初始化执行器? 有人能指出我正确的方向吗?

2 个答案:

答案 0 :(得分:1)

很可能您使用/*(默认情况下,如果未指定)用于Jersey映射。问题是泽西岛将得到所有的要求。它不知道它需要转发到任何执行器端点。

解决方案在this post中描述。更改Jersey的映射,或更改Jersey以用作过滤器而不是servlet。然后设置Jersey属性以转发对它不知道的URL的请求。

答案 1 :(得分:0)

这就是我能够使它正常工作的方式

第1步 默认情况下,Jersey将设置由ResourceConfig扩展配置为serverlate的资源。我们需要告诉Spring Boot使用它作为过滤器。 将其设置为使用以下属性

spring .jersey.type: filter 

第2步

我使用以下配置注册资源

   @component 
    public class MyResourceConfig extends ResourceConfig  {

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

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

    } 

@component更改为@Configuration,并在属性property(ServletProperties.FILTER_FORWARD_ON_404, true);下添加

最终配置

@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);                   
                }
            }       

        }