how to disable Jersey from weblogic 12.2.1

拜拜、爱过 提交于 2019-12-19 03:48:04

问题


Weblogic 12.2.1 has Jersey 2.21.1 inside as implementation of JAX-RS 2.0,but we would like to use Jersey 2.5.1 or Jersey of the latest version.

General way to solve the conflict is to define classes in configuration file to load classes from application.

But when you upgrade weblogic or Jersey, you have to look into the class conflict and make changes to configuration, is there a convenient way to disable Jersey from weblogic?


回答1:


You need to include the jersey files in the web-inf lib of your project (you can get jersey and dependencies zip file from jersey's website), also add these lines to your weblogic.xml file (as indicated in this post Using Jersey 2.x web service on Weblogic 12.1.1):

 <container-descriptor>

    <prefer-application-packages>
        <!-- jsr311 -->
        <package-name>javax.ws.rs.*</package-name>
        <!-- javassist -->
        <package-name>javassist.*</package-name>
        <!-- aop repackaged -->
        <package-name>org.aopalliance.*</package-name>

        <!-- jersey 2 -->
        <package-name>jersey.repackaged.*</package-name>
        <package-name>org.glassfish.jersey.*</package-name>
        <package-name>com.sun.research.ws.wadl.*</package-name>

        <!-- hk2 -->
        <package-name>org.glassfish.hk2.*</package-name>
        <package-name>org.jvnet.hk2.*</package-name>
        <package-name>org.jvnet.tiger_types.*</package-name>

    </prefer-application-packages>

    <prefer-application-resources>
        <resource-name>META-INF/services/javax.servlet.ServletContainerInitializer</resource-name>
        <resource-name>META-INF/services/javax.ws.rs.ext.RuntimeDelegate</resource-name>

        <!-- jersey -->
        <resource-name>META-INF/services/org.glassfish.jersey.*</resource-name>
        <resource-name>org.glassfish.jersey.*</resource-name>
        <resource-name>jersey.repackaged.*</resource-name>

        <!-- hk2 -->
        <resource-name>META-INF/services/org.glassfish.hk2.*</resource-name>
    </prefer-application-resources>
</container-descriptor>

Doing this will override the jersey version used by weblogic 12.2.1.

If you're using Json you will also require to get these jars as indicated in this post POST to Jersey REST service getting error 415 Unsupported Media Type:

  • jersey-media-json-jackson
  • jackson-jaxrs-json-provider
  • jackson-core
  • jackson-databind
  • jackson-annotations
  • jackson-jaxrs-base
  • jackson-module-jaxb-annotations
  • jersey-entity-filtering

and add these lines to the <prefer-application-packages> section in weblogic.xml:

 <package-name>org.codehaus.jackson.*</package-name>
 <package-name>com.fasterxml.jackson.*</package-name>

UDPATE- Also worth mentioning that weblogic 12 default JSON binder is MOXy and not Jersey, this has caused me some issues and I eventually replaced the provider with Jersey which makes my above changes unnecessary.



来源:https://stackoverflow.com/questions/39323977/how-to-disable-jersey-from-weblogic-12-2-1

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