Weblogic 12c - 两次部署耳朵

Weblogic 12c - Deploy an ear twice

我正在尝试在 Weblogic 12.2.1.3.0 上部署一个 ear 文件两次。应用程序与上下文根相同。

他们有:

  1. 相同的 JPA 模型
  2. 相同 persistance.xml(具有相同的持久性单元名称)
  3. 当我部署 "the second" 耳朵并尝试从第一个耳朵访问数据库时,我收到

java.lang.ClassCastException: com.myApplication.models.entityOne cannot be cast to com.myApplication.models.entityOne

第一只耳朵好像用的是自己的模型,第二只耳朵用的是EntityManager。

我的 ear 文件的结构是这样的:

/
  - lib
    - jar-with-my-models.jar
    - jar-with-persistance.jar

Persistence.xml定义如下:

 <persistence-unit name="my-persistance-unit" transaction-type="JTA">
      <jar-file>jar-with-my-models.jar</jar-file>
 </persistence-unit>

Weblogic.xml定义如下:

<weblogic-web-app
    xmlns="http://www.bea.com/ns/weblogic/90">
    <context-root>/console</context-root>
    <container-descriptor>
        <show-archived-real-path-enabled>true</show-archived-real-path-enabled>
        <prefer-web-inf-classes>false</prefer-web-inf-classes>
        <prefer-application-packages>
            <package-name>antlr.*</package-name>
        </prefer-application-packages>
    </container-descriptor>

    <session-descriptor>
        <persistent-store-type>memory</persistent-store-type>
        <sharing-enabled>true</sharing-enabled>
    </session-descriptor>
</weblogic-web-app>

我部署了两次我的 ear 文件,因为我想复制在 WebLogic 中并行部署期间收到的问题

编辑 1

我注意到通过@PersistenceContext 注入的实体管理器在应用程序之间是相同的

请求第一个应用程序 em: com.sun.proxy.$Proxy523

请求第二个应用程序 em: com.sun.proxy.$Proxy523

如果您在同一个 Weblogic Managed Server 上部署两个应用程序(如果它们共享相同的 beans - 相同的包+class 名称),Weblogic class 加载器之间可能存在问题。

我建议您为不同的应用程序创建不同的 Weblogic 托管服务器。 这样你就没有问题了。