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

时间:2017-10-31 11:06:13

标签: java spring maven jar weblogic

My Spring应用程序在Weblogic 11g上部署得很好。但是,当我尝试在Weblogic 12c上部署时,我会一个接一个地获得ClassNotFoundException

首先,我得到java.lang.ClassNotFoundException: com.querydsl.core.types.Expression,我通过添加缺少的依赖项解决了这个问题。然后我得到熟悉的异常,但这次缺少的类来自包com.mysema.querydsl。引入此依赖项后,我收到以下异常:java.lang.ClassNotFoundException: org.apache.abdera.writer.Writer

迁移到Weblogic 12c后,为什么应用程序完全被破坏(因为Spring不应该与容器耦合)?

以下是迁移前项目的所有依赖项:

<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>

3 个答案:

答案 0 :(得分:1)

一般问题是Weblogic捆绑了许多库。部署应用程序时,类加载器可能会加载与Weblogic捆绑的应用程序或从应用程序加载。

Weblogic 12c捆绑了额外的库,因此可能会抛出异常,因为jar包含相同库的旧版本,并且该jar中可能不存在某些类/方法。

解决方法是部署包装WAR文件并指定首选库的EAR。这样就可以加载库而不是Weblogic以前的版本。

为了部署EAR,您需要创建一个带有ear包装的新Maven模块,并包含需要放在src / application / META-INF下的weblogic-application.xml。

该文件需要指定应从应用程序加载的首选包,而不是Weblogic,例如:

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

在它的pom.xml中的EAR模块中,您需要通过在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>

最后,WAR模块需要在/ src / main / resources下创建weblogic.xml,并有两个部分:

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

“yourContext”需要与maven-ear-plugin中提供的相同,并且应该是应用程序的Web上下文。

答案 1 :(得分:0)

这是在春季数据jpa

的后续版本中修复的

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

答案 2 :(得分:0)

我遇到了类似的问题,但是使用了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.

对我的项目有效的方法:在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>

您可以阅读有关此的更多信息→https://docs.oracle.com/cd/E24329_01/web.1211/e21049/weblogic_xml.htm#WBAPP602

---其他信息---

在EAR模块中,我将weblogic-application.xml放在src / application / META-INF下 但以某种方式没有考虑。 WAR模块在src / src / main / webapp / WEB_INF下创建了weblogic.xml

尝试了第一个答案(在src / src / main / resources中添加了一个新的weblogic.xml)得到了IncompatibleClassChangeError