WildFly和资源排除

时间:2014-04-08 08:49:13

标签: java spring jpa wildfly

我手上有一个wildfly war应用程序,它依赖于一个用Spring启动自己的JPA持久性容器的jar。这个jar有自己的persistence.xml,只有一个持久性单元。 在嵌入式jar中,由于只有一个持久性单元,因此使用@PersistenceContext注入而不使用单元名称。此外,具有这些字段的对象不是EJB,它们是简单的Spring bean ......

另一方面,应用程序还有一个带有两个持久性单元的persistence.xml。 该应用程序的代码具有@PersistenceContext个字段,其中包含正确的unitName,这是必需的,因为它们有两个。

现在,当我启动我的应用程序时,Wildfly(特别是jpa模块)扫描jar中的代码并在@PersistenceContext上没有我的Spring bean的unitNames:

DEBUG [org.jboss.as.jpa.messages] (MSC service thread 1-1) persistence unit search for unitName=null referenced from class=the.spring.Bean (annotation=@javax.persistence.PersistenceContext() on void the.spring.Bean.setEntityManager(javax.persistence.EntityManager))

为了解决这个问题,我想排除jar:在TomEE中,有一个意思是明确地排除jar被扫描,但我在WildFly中找不到类似的功能。 我尝试了以下配置但没有成功:

  • jboss-deployment-structure.xml已被阅读,但没有明显效果:

    <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
      <deployment>
        <exclusions>
          <module name="deployment.jee-app.war.spring-app.jar" />
          <!-- I have also tried the following -->
          <!-- <module name="jee-app.war.spring-app.jar" /> -->
          <!-- <module name="spring-app.jar" /> -->
        </exclusions>
      </deployment>
    </jboss-deployment-structure> 
    
  • jboss-scanning.xml似乎被忽略了

    <scanning xmlns="urn:jboss:scanning:1.0">
      <path name="jee-app.war/WEB-INF/lib">
        <exclude name="spring-app.jar" />
      </path>
    </scanning>
    

这两个文件都在我的战争应用程序的WEB-INF文件夹中。

jee-app.war
  ├── WEB-INF
  │   ├── classes
  |   │   ├── META-INF
  |   │   |    └── persistence.xml _____________ # 2 PUs here
  |   |   └── < lots of packages >
  |   ├── lib
  |   |   ├── spring-app.jar ___________________ # to EXCLUDE from scanning !!!
  |   |   |   ├── META-INF
  |   |   |   |   └── persistence
  |   |   |   |       └── persistence.xml ______ # 1 PU here, loaded by Spring
  |   |   |   ├── application.xml ______________ # Spring definition
  |   |   |   └── the
  |   |   |       └── spring
  |   |   |           └── Bean.class
  |   |   └── < lots of other jars > 
  |   ├── jboss-deployment-structure.xml
  |   ├── jboss-scanning.xml
  |   └── web.xml
  └── < some JSPs >

当然,我无法修改spring-app.jar(太容易了......)

毋庸置疑,我已经花了相当多的时间在WildFly文档和Google上,而没有找到除了排除子系统或覆盖WildFly的本地模块之外的任何其他内容......

感谢您的帮助!

Juan Manuel

编辑:根据请求,这里是persistence.xml文件

jee-app.war中的那个:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

  <persistence-unit name="PU1" transaction-type="JTA">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <jta-data-source>java:jboss/datasources/DS1</jta-data-source>
    <class>...</class> <!-- a lot of classes included by name !-->
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
    <properties>
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
      <property name="hibernate.hbm2ddl.auto" value="update" />
      <property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider" />
      <property name="hibernate.show_sql" value="true" />
      <property name="hibernate.format_sql" value="false" />
    </properties>
  </persistence-unit>

  <persistence-unit name="PU2" transaction-type="JTA">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <jta-data-source>java:jboss/datasources/DS2</jta-data-source>
    <class>...</class> <!-- a lot of classes included by name !-->
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
    <properties>
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
      <property name="hibernate.hbm2ddl.auto" value="update" />
      <property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider" />
      <property name="hibernate.show_sql" value="true" />
      <property name="hibernate.format_sql" value="false" />
    </properties>
  </persistence-unit>
</persistence>

spring-app.jar中的那个

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
  <persistence-unit name="xa-rm">

    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <mapping-file>META-INF/persistence/orm.xml</mapping-file>

    <exclude-unlisted-classes>false</exclude-unlisted-classes>

  </persistence-unit>

0 个答案:

没有答案