简体   繁体   English

Jersey v1 Spring Boot更改球衣根目录路径以公开执行器端点

[英]Jersey v1 Spring Boot change jersey root Path to expose actuator endpoints

starting from dsyer's example: https://github.com/dsyer/spring-boot-jersey/tree/master/spring-boot-sample-jersey1 从dsyer的示例开始: https : //github.com/dsyer/spring-boot-jersey/tree/master/spring-boot-sample-jersey1

to Re-iterate I'm using Jersey v1 not v2. 重新重申,我使用的是Jersey v1,而不是v2。

I've noticed jersey covers up the spring-boot-actuator endpoints such as /env and /health. 我注意到jersey掩盖了spring-boot-actuator端点,例如/ env和/ health。 I followed Spring Boot Jersey and Monitoring URL's to successfully re-expose the spring-boot endpoints. 我按照Spring Boot Jersey和Monitoring URL的要求成功地重新暴露了spring-boot端点。 Now jersey ignores everything but /hello/** which is what I want but I also had to change the Path in my controller to @Path("/hello") 现在,jersey忽略了所有内容,但/hello/**是我想要的,但我还必须将控制器中的Path更改为@Path("/hello")

I want my controller code to stay @Path("/") and just change jersey's Application root to /hello . 我希望我的控制器代码保留@Path("/") ,仅将jersey的Application根目录更改为/hello I figure I can accomplish this with the @ApplicationPath("/hello") annotation but I can't figure out where to put/configure that using Jersey v1 and Spring Boot. 我认为可以使用@ApplicationPath("/hello")批注来完成此操作,但无法确定使用Jersey v1和Spring Boot将其放置/配置在哪里。 (all the examples I seem to find use ResourceConfig from Jersey 2 which Jersey 1 does not seem to have the same implementation) (我似乎找到的所有示例都使用Jersey 2的ResourceConfig ,而Jersey 1似乎没有相同的实现)

Any ideas? 有任何想法吗?

So based on the example you linked to (and after adding the actuator monitoring), I was able to get the endpoints to work in the following ways 因此,基于您链接到的示例(并添加了执行器监控之后),我能够使端点以以下方式工作

  1. Leave everything as is, except set the init param for the Jersey filter 保留所有设置,除了为Jersey过滤器设置init参数

     FilterRegistrationBean bean = new FilterRegistrationBean(); ... bean.addInitParameter("com.sun.jersey.config.feature.FilterForwardOn404", "true"); 

    This makes it so that even with the default /* mapping, when Jersey doesn't find the monitoring endpoints (which it shouldn't), it will forward the request back to the servlet container, and it will find the endpoints. 这样一来,即使使用默认的/*映射,当Jersey找不到监视端点(不应找到)时,它将把请求转发回servlet容器,并找到端点。

  2. In your post, it seems you tried to change the URL as a work around for "shadowing" of the monitoring URLs. 在您的帖子中,您似乎试图更改URL,以替代监视URL的“阴影”。 But the above fixes that problem without needed to change the path. 但是以上方法解决了该问题,而无需更改路径。 But if you still did want to change the path, this is the solution I was able to come up with. 但是,如果你还是没有想改变路径,这是我能拿出解决方案。

    It seem that trying to add the mapping in a filter produces the behavior you are experiencing. 似乎尝试在过滤器中添加映射会产生您遇到的行为。 To get around that, instead of register Jersey as a filter, I registered as a servlet. 为了解决这个问题,我没有将Jersey注册为过滤器,而是注册为servlet。 Note that the previous solution only works as a filter. 请注意,先前的解决方案仅用作过滤器。 But here we will use a servlet to change the URL mapping. 但是这里我们将使用servlet来更改URL映射。

     @Bean public ServletRegistrationBean jerseyServlet() { ServletRegistrationBean bean = new ServletRegistrationBean(); bean.setServlet(new ServletContainer()); bean.addInitParameter("com.sun.jersey.config.property.packages", "com.sun.jersey;demo"); bean.addUrlMappings("/api/*"); return bean; } 

I imagine there should be some combination of ResourceConfig/@ApplicationPath that should work, but with the testing I have done, I have yet to find it. 我想应该应该可以使用ResourceConfig/@ApplicationPath某种组合,但是在完成测试之后,我还没有找到它。 I may update this post later if I can figure it out. 如果可以解决的话,我可能会在以后更新此帖子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM