无法在 Websphere 传统 8.5 上使用 Spring 启动数据

Unable to use Spring Boot Data on Websphere traditional 8.5

我正在尝试 运行 Spring 在 Websphere 8.5.5.13 上启动 1.5.9 应用程序(class 加载是最后一次,我没有共享库) 并且在尝试调用 JpaRepository 内置方法时(我注意到正在执行 SQL 查询)但是我收到以下异常:

org.springframework.transaction.TransactionSystemException: 
UOWManager transaction processing failed; nested exception is com.ibm.wsspi.uow.UOWException: 
java.lang.LinkageError: com/ibm/websphere/uow/UOWSynchronizationRegistry.registerInterposedSynchronization
(Ljavax/transaction/Synchronization;)V (loaded from file:/D:/IBM/WebSphere/AppServer/plugins/com.ibm.ws.runtime.jar 
by org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader@873a9f67) 
called from class org.springframework.transaction.jta.WebSphereUowTransactionManager$UOWActionAdapter 
(loaded from file:/D:/IBM/WebSphere/AppServer/profiles/AppSrv01/installedApps/D1SHLAPXXPWV1Node01Cell
/Spring.ear/SpringJSF.war/WEB-INF/lib/spring-tx-4.3.13.RELEASE.jar by 
com.ibm.ws.classloader.CompoundClassLoader@7c146942[war:Spring/SpringJSF.war]

我的pom文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.springframework</groupId>
    <artifactId>SpringJSF</artifactId>
    <version>1</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>  
    </parent> 

    <properties>
        <java.version>1.8</java.version>   
    </properties>

    <packaging>war</packaging>

    <dependencies>

      <dependency>
         <groupId>javax.servlet</groupId>
         <artifactId>javax.servlet-api</artifactId>
         <version>3.1.0</version>
         <scope>provided</scope>
      </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-cache</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                   <groupId>org.springframework.boot</groupId>
                   <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>   
            <exclusions>
                <exclusion>
                    <groupId>org.hibernate</groupId>
                </exclusion>
            </exclusions>               
        </dependency>

       <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.2.15.Final</version>
       </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.2.15.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.0.Final</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>javax</groupId> 
            <artifactId>javaee-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>javax.el-api</artifactId>
            <version>3.0.0</version>
            <scope>provided</scope>
        </dependency> 

        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>6.2.2.jre8</version>
        </dependency>


        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.faces</artifactId>
            <version>2.2.9</version>
        </dependency>

        <dependency>
            <groupId>javax.enterprise</groupId>
            <artifactId>cdi-api</artifactId>
            <version>1.2</version>
        </dependency>


        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
        </dependency>

        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>6.1</version>
        </dependency>


        <dependency>
            <groupId>org.ocpsoft.rewrite</groupId>
            <artifactId>rewrite-servlet</artifactId>
            <version>3.4.1.Final</version>
        </dependency>

        <dependency>
            <groupId>org.ocpsoft.rewrite</groupId>
            <artifactId>rewrite-config-prettyfaces</artifactId>
            <version>3.4.1.Final</version>
        </dependency>



        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.10</version>
        </dependency> 

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.5</version>
        </dependency>

        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.7</version>
        </dependency>

        <dependency>
            <groupId>commons-validator</groupId>
            <artifactId>commons-validator</artifactId>
            <version>1.6</version>
        </dependency>

        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.3</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.5</version>
        </dependency>

        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.9.9</version>
        </dependency>

    </dependencies>

    <build>
        <finalName>SpringJSF</finalName>
        <plugins>

            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-surefire-plugin</artifactId>
               <version>2.20</version>
               <configuration>
                  <argLine>-Dfile.encoding=UTF8</argLine>
               </configuration>
            </plugin>



        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-releases</id>
            <name>Spring Releases</name>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
        <repository>
            <id>org.jboss.repository.releases</id>
            <name>JBoss Maven Release Repository</name>
            <url>https://repository.jboss.org/nexus/content/repositories/releases</url>
        </repository>


    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <name>Spring Releases</name>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>

</project>

我的存储库界面:

public interface EmployeeRepository extends JpaRepository<Employee, Long> {

    @Query("from Employee u where u.userName = :userName")
    Employee findByUserName(@Param("userName") String username);

}

Maven 依赖关系树:

[INFO] org.springframework:SpringJSF:war:1
[INFO] +- javax.servlet:javax.servlet-api:jar:3.1.0:provided
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:1.5.9.RELEAS
E:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.5.9.RELEASE:comp
ile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:1.5.9.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:1.5.9.REL
EASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.5.9.R
ELEASE:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.1.11:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.1.11:compile
[INFO] |  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] |  |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.25:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.17:runtime
[INFO] |  \- org.springframework.boot:spring-boot-actuator:jar:1.5.9.RELEASE:com
pile
[INFO] +- org.springframework.boot:spring-boot-starter-cache:jar:1.5.9.RELEASE:c
ompile
[INFO] |  +- org.springframework:spring-context:jar:4.3.13.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-beans:jar:4.3.13.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-expression:jar:4.3.13.RELEASE:compile

[INFO] |  \- org.springframework:spring-context-support:jar:4.3.13.RELEASE:compi
le
[INFO] +- org.springframework.boot:spring-boot-starter-mail:jar:1.5.9.RELEASE:co
mpile
[INFO] |  \- com.sun.mail:javax.mail:jar:1.5.6:compile
[INFO] +- org.springframework.boot:spring-boot-starter-thymeleaf:jar:1.5.9.RELEA
SE:compile
[INFO] |  +- org.thymeleaf:thymeleaf-spring4:jar:2.1.6.RELEASE:compile
[INFO] |  |  +- org.thymeleaf:thymeleaf:jar:2.1.6.RELEASE:compile
[INFO] |  |  |  +- ognl:ognl:jar:3.0.8:compile
[INFO] |  |  |  \- org.unbescape:unbescape:jar:1.1.0.RELEASE:compile
[INFO] |  |  \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] |  \- nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:jar:1.4.0:compile
[INFO] |     \- org.codehaus.groovy:groovy:jar:2.4.13:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:1.5.9.RELEASE:te
st
[INFO] |  +- org.springframework.boot:spring-boot-test:jar:1.5.9.RELEASE:test
[INFO] |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:1.5.9.R
ELEASE:test
[INFO] |  +- com.jayway.jsonpath:json-path:jar:2.2.0:test
[INFO] |  |  \- net.minidev:json-smart:jar:2.2.1:test
[INFO] |  |     \- net.minidev:accessors-smart:jar:1.1:test
[INFO] |  |        \- org.ow2.asm:asm:jar:5.0.3:test
[INFO] |  +- junit:junit:jar:4.12:test
[INFO] |  +- org.assertj:assertj-core:jar:2.6.0:test
[INFO] |  +- org.mockito:mockito-core:jar:1.10.19:test
[INFO] |  |  \- org.objenesis:objenesis:jar:2.1:test
[INFO] |  +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] |  +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO] |  +- org.skyscreamer:jsonassert:jar:1.4.0:test
[INFO] |  |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1
:test
[INFO] |  +- org.springframework:spring-core:jar:4.3.13.RELEASE:compile
[INFO] |  \- org.springframework:spring-test:jar:4.3.13.RELEASE:test
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.5.9.RELEASE:com
pile
[INFO] |  +- org.hibernate:hibernate-validator:jar:5.3.6.Final:compile
[INFO] |  |  +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  |  \- com.fasterxml:classmate:jar:1.3.4:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.10:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile

[INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.8.10:compile
[INFO] |  +- org.springframework:spring-web:jar:4.3.13.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:4.3.13.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.5.9.RELEAS
E:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-aop:jar:1.5.9.RELEASE:
compile
[INFO] |  |  \- org.aspectj:aspectjweaver:jar:1.8.13:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.5.9.RELEASE
:compile
[INFO] |  |  +- org.apache.tomcat:tomcat-jdbc:jar:8.5.23:compile
[INFO] |  |  |  \- org.apache.tomcat:tomcat-juli:jar:8.5.23:compile
[INFO] |  |  \- org.springframework:spring-jdbc:jar:4.3.13.RELEASE:compile
[INFO] |  +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] |  +- org.springframework.data:spring-data-jpa:jar:1.11.9.RELEASE:compile

[INFO] |  |  +- org.springframework.data:spring-data-commons:jar:1.13.9.RELEASE:
compile
[INFO] |  |  +- org.springframework:spring-orm:jar:4.3.13.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-tx:jar:4.3.13.RELEASE:compile
[INFO] |  |  \- org.slf4j:jcl-over-slf4j:jar:1.7.25:compile
[INFO] |  \- org.springframework:spring-aspects:jar:4.3.13.RELEASE:compile
[INFO] +- org.hibernate:hibernate-core:jar:4.2.15.Final:compile
[INFO] |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.3.1.Final:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  +- org.javassist:javassist:jar:3.21.0-GA:compile
[INFO] |  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar
:1.0.1.Final:compile
[INFO] |  \- org.hibernate.common:hibernate-commons-annotations:jar:4.0.2.Final:
compile
[INFO] +- org.hibernate:hibernate-entitymanager:jar:4.2.15.Final:compile
[INFO] +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.0.Final:
compile
[INFO] +- org.springframework.boot:spring-boot-starter-security:jar:1.5.9.RELEAS
E:compile
[INFO] |  +- org.springframework:spring-aop:jar:4.3.13.RELEASE:compile
[INFO] |  +- org.springframework.security:spring-security-config:jar:4.2.3.RELEA
SE:compile
[INFO] |  |  \- org.springframework.security:spring-security-core:jar:4.2.3.RELE
ASE:compile
[INFO] |  \- org.springframework.security:spring-security-web:jar:4.2.3.RELEASE:
compile
[INFO] +- javax:javaee-api:jar:6.0:provided
[INFO] +- javax.el:javax.el-api:jar:3.0.0:provided
[INFO] +- com.microsoft.sqlserver:mssql-jdbc:jar:6.2.2.jre8:compile
[INFO] +- org.glassfish:javax.faces:jar:2.2.9:compile
[INFO] +- javax.enterprise:cdi-api:jar:1.2:compile
[INFO] |  +- javax.interceptor:javax.interceptor-api:jar:1.2:compile
[INFO] |  \- javax.inject:javax.inject:jar:1:compile
[INFO] +- javax.servlet:jstl:jar:1.2:compile
[INFO] +- org.primefaces:primefaces:jar:6.1:compile
[INFO] +- org.ocpsoft.rewrite:rewrite-servlet:jar:3.4.1.Final:compile
[INFO] +- org.ocpsoft.rewrite:rewrite-config-prettyfaces:jar:3.4.1.Final:compile

[INFO] |  \- org.ocpsoft.rewrite:rewrite-integration-faces:jar:3.4.1.Final:compi
le
[INFO] +- commons-codec:commons-codec:jar:1.10:compile
[INFO] +- org.apache.commons:commons-lang3:jar:3.5:compile
[INFO] +- javax.mail:mail:jar:1.4.7:compile
[INFO] |  \- javax.activation:activation:jar:1.1:compile
[INFO] +- commons-validator:commons-validator:jar:1.6:compile
[INFO] |  +- commons-beanutils:commons-beanutils:jar:1.9.3:compile
[INFO] |  +- commons-digester:commons-digester:jar:2.1:compile
[INFO] |  +- commons-logging:commons-logging:jar:1.2:compile
[INFO] |  \- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] +- commons-fileupload:commons-fileupload:jar:1.3.3:compile
[INFO] +- commons-io:commons-io:jar:2.5:compile
[INFO] \- joda-time:joda-time:jar:2.9.9:compile

注意:任何用 @Query 注释的 dao 方法都可以正常工作,没有问题,我当前的问题是 JpaRepository 内置方法,例如findAll,它不起作用并产生上述异常。

更新 1:我尝试先将 class 加载标记为父级,然后将所有 jar 从我的应用程序 lib 文件夹中移出,并将它们放在一个独立的共享文件夹中库,但是这个解决方案使应用程序在没有初始化 springboot 的情况下启动,既没有 hibernate 也没有 jsf,所以它不起作用。

问题很可能是由应用程序加载器中打包的 JTA API 副本引起的。这将导致 Spring 事务 class 和 WAS 事务 class 到 link 针对 JTA class 的单独副本,以及来自 Spring class(直接来自应用程序加载器,间接通过 WAS class)在运行时导致 LinkageError。

通过从应用程序中删除 JTA API 可能会解决此特定问题。您可能还想重新考虑 PARENT_LAST 的使用,除非您确定它是您的应用程序所必需的 - 虽然它有其用途,但它也会大大增加 LinkageErrors 和 ClassCastExceptions 的可能性,如果应用程序的内容不是很严格地控制。更安全的替代方案可能是带有隔离 class 加载程序的共享库,仅包含您需要为其带来自己的实现的特定库,而不是简单地使用服务器中包含的版本。

maven 依赖关系树显示您有 2 个事务 API 作为依赖项:

  • javax.transaction-api
  • jboss-transaction-api_1.1_spec

并且都具有编译范围。

当您查看 war 的 lib 文件夹时,您应该找到

  • javax.transaction-api-1.2.jar
  • jboss-transaction-api_1.1_spec-1.0.1.Final.jar

您必须确保两者都不在 lib 文件夹中,因为 com.ibm.websphere.uow.UOWSynchronizationRegistry 是从另一个 class 加载器加载的,并且此 class 加载器还包含交易版本 api.

尝试使用 dependencyManagement 将依赖范围设置为 provided。例如

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>javax.transaction-api</artifactId>
            <version>1.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.spec.javax.transaction</groupId>
            <artifactId>jboss-transaction-api_1.1_spec</artifactId>
            <version>1.0.1.Final</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>
</dependencyManagement>