在Spring Boot项目中引用persistence.xml中的jar文件

时间:2017-05-30 06:30:09

标签: jpa spring-boot jpa-2.0 openjpa persistence.xml

我尝试使用openJPA和外部持久性单元jar文件设置Spring Boot应用程序。但我在Maven构建中遇到错误消息:

The jar resource "lib/foo-persistence-unit-1.0.0jar" cannot be loaded.

我想在构建期间无法使用持久性单元jar。构建Spring Boot jar时甚至可以实现这一点吗?

pom.xml中的依赖

<dependency>
        <groupId>com.example.bar</groupId>
        <artifactId>foo</artifactId>
        <version>1.0.0</version>
</dependency>

Openjpa maven插件

<plugin>
   <groupId>org.apache.openjpa</groupId>
   <artifactId>openjpa-maven-plugin</artifactId>
   <configuration>
     <addDefaultConstructor>true</addDefaultConstructor>
     <enforcePropertyRestrictions>true</enforcePropertyRestrictions>
     <persistenceXmlFile>src/main/resources/META-INF/persistence.xml</persistenceXmlFile>
   </configuration>
   <executions>
     <execution>
       <id>enhancer</id>
       <phase>process-classes</phase>
       <goals>
         <goal>enhance</goal>
       </goals>
     </execution>
    </executions>
    <dependencies>
       <dependency>
          <groupId>org.apache.openjpa</groupId>
          <artifactId>openjpa</artifactId>
          <version>${openjpa.version}</version>
       </dependency>
    </dependencies>
</plugin>

的persistence.xml:

<persistence-unit name="foo">
        <jar-file>lib/foo-persistence-unit-1.0.0.jar</jar-file>
        <properties>
            <property name="openjpa.DynamicEnhancementAgent" value="true"/>
            <property name="openjpa.ConnectionFactoryMode" value="managed"/>
            <property name="openjpa.QueryCache" value="false"/>
            <property name="openjpa.Log" value="DefaultLevel=TRACE, Tool=TRACE, SQL=TRACE"/>
            <property name="openjpa.TransactionMode" value="managed"/>
            <property name="openjpa.ManagedRuntime" value="auto"/>
            <property name="openjpa.Compatibility" value="QuotedNumbersInQueries=true"/>
        </properties>
    </persistence-unit>

0 个答案:

没有答案