使用 ServletContainer 作为 Servlet 提供静态资源

Serving static resources with ServletContainer as Servlet

我注意到 org.glassfish.jersey.servlet.ServletContainer 需要用作 Filter(在 spring 启动的 application.properties 中设置 spring.jersey.type=filter)而不是 Servlet 以提供对静态资源的访问(例如 /static/somefile.jsp/static/myfile.css)。

由于我被迫使用 ServletContainer 作为 Servlet,是否有任何变通方法允许具有此限制的静态资源?

最后我使用了@peeskillet提供的第一个方案

我用 @ApplicationPath("/v1") 注释了我的 ResourceConfig 子类,并设法保持端点不变:幸运的是它们都被定义为 @Path("/v1/endpoint1)",@Path("/v1/endpoint2"),等等. 所以我从他们的 @Path 中删除了 /v1 (例如 @Path("/endpoint1"),他们仍然可以在他们的原始地址访问(例如 /v1/endpoint1 )感谢@ApplicationPath 前缀 /v1.