Weblogic 12c JPA 2.1 spring boot。

时间:2022-03-24 21:38:34

I want to deploy a spring boot application to weblogic 12c (12.1.2).

我想将spring引导应用程序部署到weblogic 12c(12.1.2)。

The application using latest spring boot libraries. I try to using prefer-web-inf-classes but I run out of luck.

使用最新spring引导库的应用程序。我试着使用优先级网络课程,但我的运气不好。

If I try to using prefer-webinf-classes I got (my application is using validation api 1.1.0.Final):

如果我尝试使用我得到的优先级-webinf类(我的应用程序使用验证api 1.1.0.Final):

weblogic.application.ModuleException: java.lang.NoSuchMethodError: javax.validation.spi.ConfigurationState.getParameterNameProvider()Ljavax/validation/ParameterNameProvider;
        at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:140)
        at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
        at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:216)
        at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:211)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)
        Truncated. see log file for complete stacktrace
Caused By: java.lang.NoSuchMethodError: javax.validation.spi.ConfigurationState.getParameterNameProvider()Ljavax/validation/ParameterNameProvider;
        at org.hibernate.validator.internal.engine.ValidatorFactoryImpl.<init>(ValidatorFactoryImpl.java:142)
        at org.hibernate.validator.HibernateValidator.buildValidatorFactory(HibernateValidator.java:35)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        Truncated. see log file for complete stacktrace

If I try to using this configuration in web.xml:

如果我尝试在web.xml中使用这种配置:

    <wls:prefer-application-packages>
        <wls:package-name>antlr.*</wls:package-name>
        <wls:package-name>org.apache.commons.*</wls:package-name>
        <wls:package-name>org.apache.xmlbeans.*</wls:package-name>
        <wls:package-name>org.springframework.*</wls:package-name>
        <wls:package-name>org.hibernate.*</wls:package-name>
        <wls:package-name>org.hibernate.validator.*</wls:package-name>
        <wls:package-name>javax.validation.*</wls:package-name>
        <wls:package-name>javax.persistence.*</wls:package-name>
        <wls:package-name>javax.validation.spi.*</wls:package-name>
        <wls:package-name>org.slf4j.*</wls:package-name>
        <wls:package-name>org.joda.*</wls:package-name>
        <wls:package-name>com.fasterxml.*</wls:package-name>
    </wls:prefer-application-packages>

I got hibernate weblogic "org.eclipse.persistence.jpa.PersistenceProvider cannot be cast to javax.persistence.spi.PersistenceProvider" exception from validator.

我得到了hibernate weblogic "org.eclipse.persistence.jpa.PersistenceProvider不能被转换为javax.persistence.spi。从验证器PersistenceProvider“例外。

How can I solve this? (upgrade weblogic is not an option)

我怎么解决这个问题呢?(升级weblogic不是一个选项)

Thanks

谢谢

4 个解决方案

#1


3  

Sorry for my late answer. My final solution:

对不起,我迟到了。我最后的解决方案:

  1. add weblogic.xml into your war with these content:

    添加服务器。xml与这些内容的战争:

    <?xml version="1.0" encoding="UTF-8"?>
    <wls:weblogic-web-app
        xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
        http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd
        http://xmlns.oracle.com/weblogic/weblogic-web-app
        http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
    <wls:container-descriptor>
        <wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes>
    </wls:container-descriptor>
    </wls:weblogic-web-app>
    
  2. Create ear (It's important) and add weblogic-application.xml:

    创建ear(这很重要),并添加weblogicapplication .xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <weblogic-application xmlns="http://xmlns.oracle.com/weblogic/weblogic-application"
                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-application
        http://xmlns.oracle.com/weblogic/weblogic-application/1.4/weblogic-application.xsd">
    <prefer-application-packages>
        <package-name>org.slf4j.*</package-name>
        <package-name>com.fasterxml.*</package-name>
        <package-name>org.joda.*</package-name>
        <package-name>org.hibernate.*</package-name>
        <package-name>org.jboss.*</package-name>
        <package-name>javax.validation.*</package-name>
    </prefer-application-packages>
    </weblogic-application>
    

This is work for me...

这是我的工作……

#2


1  

Obviously, there is a classloading conflict between the API and the implementation (eclipse.jpa.PersistenceProvider).

显然,API和实现之间存在类加载冲突(eclipse.jpa.PersistenceProvider)。

However, the reason for such conflict is yet to explain, since the 'prefer-application-packages' is supposed to tell the container to use what comes within the application package (i.e. both the API and implementation).

然而,这种冲突的原因还没有解释,因为“首选应用程序包”应该告诉容器使用应用程序包中的内容(即API和实现)。

A workaround that worked for me in WLS 12.2.1 is as follows :

在WLS 12.2.1中为我工作的一种变通方法如下:

  1. Exclude the dependency to the JAP2 API :

    排除对JAP2 API的依赖:

    <dependency>  
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
      <exclusions>
          <exclusion>
              <groupId>org.hibernate.javax.persistence</groupId>
              <artifactId>hibernate-jpa-2.1-api</artifactId>
          </exclusion>
      </exclusions>
    </dependency>
    
  2. Make sure your the 'prefer-application-packages' in weblogic.xml does not include javax.persistence.* (but should include javax.validation.* and org.hibernate.*)

    确保您的“首选应用程序包”在weblogic中。xml不包括javax.persistence。*(但应该包括javax.validation。*和org.hibernate。*)

Using this workaround, you are relying on the JPA2 implementation of the container..

使用这种方法,您将依赖于容器的JPA2实现。

Beware, thought, that this might be confusing if versions are different since behaviour might differ between unit tests (using JPA2 implementation that comes with Spring Boot : hibernate-jpa) and tests in container (using whatever JPA implementation WebLogic provides: likely eclipse JPA Provider).

请注意,如果版本不同,那么这可能会让人感到困惑,因为在单元测试(使用Spring Boot的JPA2实现)和容器测试(使用WebLogic提供的任何JPA实现:可能的eclipse JPA提供者)中,行为可能会有所不同(使用JPA2实现)。

#3


1  

I had same issue with Spring Boot and WebLogic 12c with error org.eclipse.persistence.jpa.PersistenceProvider cannot be cast to javax.persistence.spi.PersistenceProvider

对于Spring Boot和WebLogic 12c,我也有同样的问题。

I was getting this error only if I was using any of validation annotations.

只有在使用任何验证注释时,我才会得到这个错误。

Solved by adding this to weblogic.xml:

通过将此添加到weblogic.xml解决。

    <prefer-application-resources>
        <resource-name>META-INF/services/javax.persistence.spi.PersistenceProvider</resource-name>
    </prefer-application-resources>

#4


0  

A bit too late to answer you question I guess but it sounds like you are using a new interface and old implementation. This happens sometimes when you deploy to a container and not using class-path filtering for instance. In turn you will use an older implementation provided by the container. The behavior is very random depending on what gets loaded when. Hope this helps you in right direction or anyone else having similar problem.

回答你的问题有点太晚了,但听起来好像你在使用一个新的接口和旧的实现。有时,当您部署到容器时,不使用类路径筛选时,就会出现这种情况。反过来,您将使用容器提供的旧实现。这种行为非常随机,取决于什么时候加载。希望这能帮助你找到正确的方向或者其他有类似问题的人。

#1


3  

Sorry for my late answer. My final solution:

对不起,我迟到了。我最后的解决方案:

  1. add weblogic.xml into your war with these content:

    添加服务器。xml与这些内容的战争:

    <?xml version="1.0" encoding="UTF-8"?>
    <wls:weblogic-web-app
        xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
        http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd
        http://xmlns.oracle.com/weblogic/weblogic-web-app
        http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
    <wls:container-descriptor>
        <wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes>
    </wls:container-descriptor>
    </wls:weblogic-web-app>
    
  2. Create ear (It's important) and add weblogic-application.xml:

    创建ear(这很重要),并添加weblogicapplication .xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <weblogic-application xmlns="http://xmlns.oracle.com/weblogic/weblogic-application"
                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-application
        http://xmlns.oracle.com/weblogic/weblogic-application/1.4/weblogic-application.xsd">
    <prefer-application-packages>
        <package-name>org.slf4j.*</package-name>
        <package-name>com.fasterxml.*</package-name>
        <package-name>org.joda.*</package-name>
        <package-name>org.hibernate.*</package-name>
        <package-name>org.jboss.*</package-name>
        <package-name>javax.validation.*</package-name>
    </prefer-application-packages>
    </weblogic-application>
    

This is work for me...

这是我的工作……

#2


1  

Obviously, there is a classloading conflict between the API and the implementation (eclipse.jpa.PersistenceProvider).

显然,API和实现之间存在类加载冲突(eclipse.jpa.PersistenceProvider)。

However, the reason for such conflict is yet to explain, since the 'prefer-application-packages' is supposed to tell the container to use what comes within the application package (i.e. both the API and implementation).

然而,这种冲突的原因还没有解释,因为“首选应用程序包”应该告诉容器使用应用程序包中的内容(即API和实现)。

A workaround that worked for me in WLS 12.2.1 is as follows :

在WLS 12.2.1中为我工作的一种变通方法如下:

  1. Exclude the dependency to the JAP2 API :

    排除对JAP2 API的依赖:

    <dependency>  
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
      <exclusions>
          <exclusion>
              <groupId>org.hibernate.javax.persistence</groupId>
              <artifactId>hibernate-jpa-2.1-api</artifactId>
          </exclusion>
      </exclusions>
    </dependency>
    
  2. Make sure your the 'prefer-application-packages' in weblogic.xml does not include javax.persistence.* (but should include javax.validation.* and org.hibernate.*)

    确保您的“首选应用程序包”在weblogic中。xml不包括javax.persistence。*(但应该包括javax.validation。*和org.hibernate。*)

Using this workaround, you are relying on the JPA2 implementation of the container..

使用这种方法,您将依赖于容器的JPA2实现。

Beware, thought, that this might be confusing if versions are different since behaviour might differ between unit tests (using JPA2 implementation that comes with Spring Boot : hibernate-jpa) and tests in container (using whatever JPA implementation WebLogic provides: likely eclipse JPA Provider).

请注意,如果版本不同,那么这可能会让人感到困惑,因为在单元测试(使用Spring Boot的JPA2实现)和容器测试(使用WebLogic提供的任何JPA实现:可能的eclipse JPA提供者)中,行为可能会有所不同(使用JPA2实现)。

#3


1  

I had same issue with Spring Boot and WebLogic 12c with error org.eclipse.persistence.jpa.PersistenceProvider cannot be cast to javax.persistence.spi.PersistenceProvider

对于Spring Boot和WebLogic 12c,我也有同样的问题。

I was getting this error only if I was using any of validation annotations.

只有在使用任何验证注释时,我才会得到这个错误。

Solved by adding this to weblogic.xml:

通过将此添加到weblogic.xml解决。

    <prefer-application-resources>
        <resource-name>META-INF/services/javax.persistence.spi.PersistenceProvider</resource-name>
    </prefer-application-resources>

#4


0  

A bit too late to answer you question I guess but it sounds like you are using a new interface and old implementation. This happens sometimes when you deploy to a container and not using class-path filtering for instance. In turn you will use an older implementation provided by the container. The behavior is very random depending on what gets loaded when. Hope this helps you in right direction or anyone else having similar problem.

回答你的问题有点太晚了,但听起来好像你在使用一个新的接口和旧的实现。有时,当您部署到容器时,不使用类路径筛选时,就会出现这种情况。反过来,您将使用容器提供的旧实现。这种行为非常随机,取决于什么时候加载。希望这能帮助你找到正确的方向或者其他有类似问题的人。