Prevent Execution of ServletContainerInitializer o

2019-02-17 08:01发布

问题:

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.