Weblogic 12.2.1.3 从 Moxy 到 Jackson

Weblogic 12.2.1.3 from Moxy to Jackson

我想将 JSON 解析器从 Moxy 更改为 Jackson,并且我遵循了 shared library approach,但没有任何结果,仍然使用 Moxy。

注意:不需要共享库!!!

共享库

我创建了一个具有以下依赖项和描述符的 Maven 项目。

pom.xml

 <properties>
    <jackson.annotations.release>2.8.6</jackson.annotations.release>
    <jersey.version>2.22.4</jersey.version>
 </properties>

 <dependencies>
    <dependency>
        <groupId>com.fasterxml.jackson.module</groupId>
        <artifactId>jackson-module-jaxb-annotations</artifactId>
        <version>${jackson.annotations.release}</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.jaxrs</groupId>
        <artifactId>jackson-jaxrs-json-provider</artifactId>
        <version>${jackson.annotations.release}</version>
    </dependency>

    <!-- Jersey dependencies -->
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet</artifactId>
        <version>${jersey.version}</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-client</artifactId>
        <version>${jersey.version}</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-multipart</artifactId>
        <version>${jersey.version}</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-jackson</artifactId>
        <version>${jersey.version}</version>
    </dependency>
</dependency>

weblogic.xml

 <container-descriptor>
    <prefer-application-packages>
        <!-- apis -->
        <package-name>javax.ws.rs.*</package-name>

        <!-- guava -->
        <package-name>com.google.common.*</package-name>

        <!-- jersey providers -->
        <package-name>org.glassfish.jersey.*</package-name>
        <package-name>jersey.repackaged.*</package-name>

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

        <!-- media providers -->
        <!--<package-name>org.eclipse.persistence.jaxb.rs.*</package-name>-->
        <package-name>com.fasterxml.jackson.*</package-name>

        <!-- wls -->
        <package-name>weblogic.jaxrs.api.client.*</package-name>
        <package-name>weblogic.jaxrs.internal.api.client.*</package-name>
        <package-name>weblogic.jaxrs.dispatch.*</package-name>
        <package-name>weblogic.jaxrs.monitoring.util.*</package-name>
    </prefer-application-packages>
</container-descriptor>

MANIFEST.MF

Manifest-Version: 1.0
Implementation-Title: Jackson Weblogic
Implementation-Version: 1.0
Specification-Title: Jackson Weblogic
Extension-Name: jackson-weblogic
Specification-Version: 1.0

Web 应用程序

我添加 web.xmlweblogic.xml

web.xml

<servlet>
    <servlet-name>com.dummy.MyApplication</servlet-name>
        <init-param>
            <param-name>jersey.config.server.provider.classnames</param-name>
            <param-value>com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider</param-value>
        </init-param>
</servlet>

<servlet-mapping>
    <servlet-name>com.dummy.MyApplication</servlet-name>
    <url-pattern>/api/*</url-pattern>
</servlet-mapping>

weblogic.xml

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">
    <library-ref>
        <library-name>jstl</library-name>
        <specification-version>1.2</specification-version>
        <implementation-version>1.2</implementation-version>
        <exact-match>false</exact-match>
    </library-ref>
    <library-ref>
        <library-name>jackson-weblogic</library-name>
        <specification-version>1.0</specification-version>
        <exact-match>false</exact-match>
    </library-ref>
</weblogic-web-app>

然后我在weblogic.xml中引用了共享库,但仍然使用Moxy。我是不是做错了什么?

更新: 我添加了网络应用程序的 web.xmlweblogic.xml

解决方案

我检查了文件夹 oracle_common\modules 并且找到了所有需要的 Jackson 依赖项。所以我更喜欢配置 Jersey 以禁用 MOXy 的使用,如下所示:

import javax.ws.rs.core.Application;
public class MyApplication extends Application
{
    @Override
    public Map<String, Object> getProperties()
    {
        Map<String, Object> proprties = new HashMap<>();
        proprties.put("jersey.config.server.disableMoxyJson", true);

        return proprties;
    }
}

关注:

决赛weblogic.xml

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">

    <context-root>/web-app</context-root>
    <container-descriptor>
        <prefer-application-packages>
            <package-name>org.apache.commons.net.*</package-name>
        </prefer-application-packages>
    </container-descriptor>

    <library-ref>
        <library-name>jstl</library-name>
        <specification-version>1.2</specification-version>
        <implementation-version>1.2</implementation-version>
        <exact-match>false</exact-match>
    </library-ref>
</weblogic-web-app>

在 pom.xml

中提及 JAX-RS 2.0 作为依赖项
<dependency>
    <groupId>javax.ws.rs</groupId>
    <artifactId>javax.ws.rs-api</artifactId>
    <version>2.0.1</version>
    <scope>provided</scope>
</dependency>

在 WebLogic 12.2.1 中,您不需要将其部署为共享库。