Maven不导出persistence.xml(PersistenceException:EntityManager没有持久性提供程序)

时间:2016-11-05 10:54:18

标签: spring hibernate maven jpa spring-boot

我有以下问题:

我创建了一个分为三层的应用程序,每一层都有自己的maven项目:

·持久层只有实体和DAO类

·域层具有业务类和Web服务

·UI层有WEB

每个图层都使用maven进行管理,而Domain依赖于持久层

如果我运行持久层,一切正常,(应运行JUnit测试)

但是当我在Domain层中添加依赖项时,无法运行抛出PersistenceException,似乎maven不会将持久性导出到de Domain项目。

这是POM for Persistence图层:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>gamerscreed.rocketstats</groupId>
<artifactId>RocketStatsCore</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>RocketStatsCore</name>
<dependencies>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.40</version>
    </dependency>       
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.2.3.Final</version>
    </dependency>   
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>5.3.0.Final</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>

</dependencies>
<build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
        <resource>
            <directory>src</directory>
            <includes>
                <include>META-INF/persistence.xml</include>
            </includes>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

这是域层的pom:

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

<groupId>gamerscreed.rocketstats</groupId>
<artifactId>RocketStatsDomain</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>RocketStatsDomain</name>
<description>Demo project for Spring Boot</description>

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

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
</properties>

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

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

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
    </dependency>

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

    <dependency>
        <groupId>gamerscreed.rocketstats</groupId>
        <artifactId>RocketStatsCore</artifactId>
    </dependency>

    <dependency>
        <groupId>gamerscreed.profiler</groupId>
        <artifactId>GamersCreedShared</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>gamerscreed.rocketstats</groupId>
            <artifactId>RocketStatsCore</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
</dependencyManagement>

这是抛出的异常:

  

org.springframework.beans.factory.BeanCreationException:在文件[C:\ Users \ Xelit3 \ Documents \ Eclipse workspace \ git \ GamersCreed \ RocketStatsDomain \ target \ classes \ gamerscreed \ rocketstats>中定义名称为'playerBusinessLayer'的bean时出错\ domain \ implementation \ PlayerBusinessLayer.class]:bean的实例化失败;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化[gamerscreed.rocketstats.domain.implementation.PlayerBusinessLayer]:构造函数抛出异常;嵌套异常是javax.persistence.PersistenceException:没有名为RocketStats的EntityManager的持久性提供程序

我看到this thread但这里没有任何帮助我:

提前致谢

编辑:添加了persistence.xml:

<?xml version="1.0" encoding="UTF-8" ?> <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" version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="RocketStats" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

    <class>gamerscreed.rocketstats.model.dto.Match</class>
    <class>gamerscreed.rocketstats.model.dto.MatchResultPlayer</class>
    <class>gamerscreed.rocketstats.model.dto.MatchResultPlayerPK</class>
    <class>gamerscreed.rocketstats.model.dto.MatchType</class>
    <class>gamerscreed.rocketstats.model.dto.Player</class>
    <class>gamerscreed.rocketstats.model.dto.Result</class>
    <class>gamerscreed.rocketstats.model.dto.Role</class>
    <class>gamerscreed.rocketstats.model.dto.Team</class>
    <class>gamerscreed.rocketstats.model.dto.Tournament</class>

    <validation-mode>AUTO</validation-mode>

    <properties>
        <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
        <property name="javax.persistence.jdbc.user" value="chustasoft" />
        <property name="javax.persistence.jdbc.password" value="chustaK4" />
        <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/cs_rocketstats" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
        <property name="hibernate.max_fetch_depth" value="3" />
        <property name="show_sql" value="true"></property>
    </properties>

</persistence-unit>

1 个答案:

答案 0 :(得分:1)

看起来persistence.xml中的类路径中缺少/找不到持久性提供程序。

<provider>PersistenceProviderImpl</provider>
<jta-data-source>..</jta-data-source>
<non-jta-data-source>..</non-jta-data-source>
<class></class>

<properties>
    <property name="openjpa.jdbc.SynchronizeMappings" value="validate" />            
</properties>