Prevent Execution of ServletContainerInitializer or how to use absolute-order

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 02:45:24

问题


is it possible to prevent the execution of the ServletContainerInitializer of a provided jar.

I want to prevent the execution of JerseyServletContainerInitializer.java which is provided by Glassfish 4.1 as an osgi-bundle (in jersey-container-servlet.jar).

Or how can I use the <absolute-order> of web.xml to enforce loading of the ResteasyServletInitializer.java provided in resteasy-servlet-initializer-3.0.11.Final.jar prior to the execution of the jersey counterpart?

I do not understand how this can be achieved using the web.xml. Also the specification of ServletContainerInitializer states:

In either case, ServletContainerInitializer services from web fragment JAR files excluded from an absolute ordering must be ignored, and the order in which these services are discovered must follow the application's classloading delegation model.

I therefore tried in my glassfish-web.xml but with no effect.

Please guide me on this one.

Cheers

(p.s. removing jersey-container-servlet.jar from the glassfish/modules/ folder "works")


回答1:


Web fragment ordering won't work, because the jersey-container-servlet.jar is not a real web fragment.

But the following works in Webogic 12.2, which uses Jersey 2.

Create class for your app

package my.app;

public class MyJaxRSApplication extends javax.ws.rs.core.Application {}

Register Rest Easy servlet with the fully qualified name of this class in web.xml

<servlet>
    <servlet-name>my.app.MyJaxRSApplication</servlet-name>
    <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>

This will not prevent execution of JerseyServletContainerInitializer, but it won't register the Jersey servlet.



来源:https://stackoverflow.com/questions/31458850/prevent-execution-of-servletcontainerinitializer-or-how-to-use-absolute-order

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