简体   繁体   English

Weblogic 12c 上的 Spring 应用程序部署失败

[英]Spring application deployment fails on Weblogic 12c

My Spring application deploys fine on Weblogic 11g.我的 Spring 应用程序在 Weblogic 11g 上部署得很好。 However, when I try to deploy on Weblogic 12c, I keep getting ClassNotFoundException 's one after another.但是,当我尝试在 Weblogic 12c 上部署时,我不断收到ClassNotFoundException的一个又一个。

First of, I get java.lang.ClassNotFoundException: com.querydsl.core.types.Expression , which I solved by adding the missing dependency.首先,我得到java.lang.ClassNotFoundException: com.querydsl.core.types.Expression ,我通过添加缺少的依赖项解决了这个问题。 Then I get familiar exception, but this time the missing class was from package com.mysema.querydsl .然后我得到了熟悉的异常,但这次丢失的类来自包com.mysema.querydsl After introducing this dependency, I get the following exception: java.lang.ClassNotFoundException: org.apache.abdera.writer.Writer .引入此依赖项后,我得到以下异常: java.lang.ClassNotFoundException: org.apache.abdera.writer.Writer

Why did the application got completely broken after migrating to Weblogic 12c (as Spring shouldn't be coupled with the container)?为什么迁移到 Weblogic 12c 后应用程序完全损坏(因为 Spring 不应该与容器耦合)?

Here are all the dependencies of the project before migrating:以下是迁移前项目的所有依赖项:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <spring.version>4.3.2.RELEASE</spring.version>
    <spring-data-jpa.version>1.10.2.RELEASE</spring-data-jpa.version>
    <spring-security.version>4.1.3.RELEASE</spring-security.version>
    <cxf.version>3.1.7</cxf.version>
    <jackson.version>1.9.13</jackson.version>
    <esapi.version>2.1.0.1</esapi.version>
    <hibernate-entitymanager.version>5.1.1.Final</hibernate-entitymanager.version>
    <hibernate-commons-annotations.version>5.0.1.Final</hibernate-commons-annotations.version>
    <spring-boot-starter-jdbc.version>1.5.2.RELEASE</spring-boot-starter-jdbc.version>
    <slf4j.version>1.7.21</slf4j.version>
    <log4j.version>1.2.17</log4j.version>
    <log.directory>logs</log.directory>
</properties>

<dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>3.0-alpha-1</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <!-- Security -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>${spring-security.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>${spring-security.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>${spring-security.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-acl</artifactId>
            <version>${spring-security.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-ldap</artifactId>
            <version>${spring-security.version}</version>
        </dependency>
        <dependency>
            <groupId>com.auth0</groupId>
            <artifactId>java-jwt</artifactId>
            <version>2.2.0</version>
        </dependency>


        <!-- DB -->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>${spring-data-jpa.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-jdbc</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-orm</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate-entitymanager.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.common</groupId>
            <artifactId>hibernate-commons-annotations</artifactId>
            <version>${hibernate-commons-annotations.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- DB end -->

        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
        <!-- Oracle JDBC -->
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc7</artifactId>
            <version>12.1.0.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
        </dependency>
    </dependencies>

This was fixed in later releases by spring data jpa spring data jpa 在以后的版本中修复了这个问题

https://jira.spring.io/browse/DATAJPA-1175 https://jira.spring.io/browse/DATAJPA-1175

use v1.10.12 or above使用 v1.10.12 或更高版本

The general problem is that Weblogic has many libraries bundled.一般的问题是 Weblogic 捆绑了许多库。 When an application is deployed the class loader might either load the one bundled with Weblogic or from the application.部署应用程序时,类加载器可能会加载与 Weblogic 捆绑在一起的应用程序或从应用程序加载。

Weblogic 12c has additional libraries bundled and therefore an exception might be thrown because the jar contains older version of the same library and some classes/methods might not be present in that jar. Weblogic 12c 捆绑了其他库,因此可能会引发异常,因为 jar 包含同一库的旧版本,并且该 jar 中可能不存在某些类/方法。

The workaround is to deploy EAR that packages your WAR file and specifying the preferred libraries.解决方法是部署 EAR 来打包您的 WAR 文件并指定首选库。 This way your libraries will loaded instead of the Weblogic previous version.这样,您的库将加载而不是 Weblogic 以前的版本。

In order to deploy EAR you need to create a new Maven module with ear packaging and include weblogic-application.xml which needs to be placed under src/application/META-INF.为了部署EAR,您需要创建一个带有ear 包装的新Maven 模块,并包含需要放置在src/application/META-INF 下的weblogic-application.xml。

The file needs to specify preferred packages that should be loaded from the application and not Weblogic for example:该文件需要指定应该从应用程序而不是 Weblogic 加载的首选包,例如:

<prefer-application-packages>
    <package-name>com.querydsl.*</package-name>
    ...
</prefer-application-packages>

In the EAR module in it's pom.xml you need specify that this file needs to be included by providing the following information in ear plugin:在 EAR 模块的 pom.xml 中,您需要通过在 ear 插件中提供以下信息来指定需要包含此文件:

      <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <version>2.10.1</version>
            <configuration>
                <defaultLibBundleDir>lib</defaultLibBundleDir>
                <earSourceDirectory>src/application</earSourceDirectory>
                <modules>
                    <webModule>
                        <groupId>your-group-id</groupId>
                        <artifactId>your-artifact-id</artifactId>
                        <contextRoot>/**yourContext**</contextRoot>
                    </webModule>
                </modules>
            </configuration>
        </plugin>
    </plugins>

Last thing, the WAR module needs to have weblogic.xml created under /src/main/resources with two sections:最后,WAR 模块需要在 /src/main/resources 下创建包含两个部分的 weblogic.xml:

<context-root>**yourContext**</context-root>
<container-descriptor>
    <prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>

The "yourContext" need to match the same one provided in maven-ear-plugin and should be the web context of the application. “yourContext”需要与 maven-ear-plugin 中提供的相同,并且应该是应用程序的 Web 上下文。

I had a similar issue but with NamedParameterJdbcTemplate.我有一个类似的问题,但 NamedParameterJdbcTemplate。

   java.lang.NoSuchMethodException: org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForLong(java.lang.String, org.springframework.jdbc.core.namedparam.SqlParameterSource)

Errors were encountered while performing this operation.

What worked for my project: in weblogic.xml file from WEB-INF add:什么对我的项目有用:在来自 WEB-INF 的 weblogic.xml 文件中添加:

<wls:prefer-web-inf-classes>false</wls:prefer-web-inf-classes>
<wls:prefer-application-packages>
   <wls:package-name>org.springframework.jdbc.core.*</wls:package-name>
   <wls:package-name>org.springframework.jdbc.core.namedparam.*</wls:package-name>
</wls:prefer-application-packages>

You can read more about this → https://docs.oracle.com/cd/E24329_01/web.1211/e21049/weblogic_xml.htm#WBAPP602您可以阅读更多相关信息 → https://docs.oracle.com/cd/E24329_01/web.1211/e21049/weblogic_xml.htm#WBAPP602

--- Additional info --- --- 附加信息 ---

In the EAR module I have weblogic-application.xml placed under src/application/META-INF but somehow it's not taken into consideration.在 EAR 模块中,我将 weblogic-application.xml 放在 src/application/META-INF 下,但不知何故它没有被考虑在内。 And the WAR module has weblogic.xml created under src/src/main/webapp/WEB_INF并且 WAR 模块在 src/src/main/webapp/WEB_INF 下创建了 weblogic.xml

Tried the first answer (add a new weblogic.xml in src/src/main/resources) got IncompatibleClassChangeError .尝试第一个答案(在 src/src/main/resources 中添加一个新的 weblogic.xml)得到IncompatibleClassChangeError

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM