【问题标题】:Actuator with Spring boot Jersey带弹簧靴的执行器
【发布时间】:2017-09-08 08:11:02
【问题描述】:

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

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

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

org.springframework.boot 弹簧引导启动器执行器 1.5.2.发布 org.springframework.boot spring-boot-starter-web 1.5.2.发布

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

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

【问题讨论】:

    标签: java jersey spring-boot-actuator


    【解决方案1】:

    您很可能正在使用 /*(如果未指定,则为默认值)进行 Jersey 映射。问题是泽西岛会得到所有的请求。它不知道它需要转发到任何执行器端点。

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

    【讨论】:

      【解决方案2】:

      这就是我能够让它工作的方式

      第 1 步 默认情况下,Jersey 将设置由 extends 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);                   
                      }
                  }       
      
              } 
      

      【讨论】:

        猜你喜欢
        • 2018-02-14
        • 2017-07-29
        • 2017-07-06
        • 1970-01-01
        • 2014-06-27
        • 2020-05-18
        • 1970-01-01
        • 1970-01-01
        • 2021-07-15
        相关资源
        最近更新 更多