Openshift - EntityManager的无持久性提供程序

时间:2013-09-24 05:24:32

标签: java tomcat jpa openshift

我将应用程序部署到Openshift.com时遇到问题。

我想在Tomcat上创建简单的Java JPA应用程序。 应用程序在本地启动,但是当我将其部署到Openshift.com时,我有这个错误:

javax.persistence.PersistenceException: 
No Persistence provider for EntityManager named testpersist

我的pom.xml:

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>testradioapp</groupId>
    <artifactId>testradioapp</artifactId>
    <packaging>war</packaging>
    <version>1.0</version>
    <name>testradioapp</name>
    <repositories>
        <repository>
            <id>eap</id>
            <url>http://maven.repository.redhat.com/techpreview/all</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>eap</id>
            <url>http://maven.repository.redhat.com/techpreview/all</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.6</maven.compiler.source>
        <maven.compiler.target>1.6</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.2-1003-jdbc4</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.25</version>
        </dependency>        
         <dependency>  
            <groupId>javax.persistence</groupId>  
            <artifactId>persistence-api</artifactId>  
            <version>1.0</version>  
        </dependency>     
    </dependencies>
    <profiles>
        <profile>
            <!-- When built in OpenShift the 'openshift' profile will be used when 
                invoking mvn. -->
            <!-- Use this profile for any OpenShift specific customization your app 
                will need. -->
            <!-- By default that is to put the resulting archive into the 'webapps' 
                folder. -->
            <!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
            <id>openshift</id>
            <build>
                <finalName>testradioapp</finalName>
                <plugins>
                    <plugin>
                        <artifactId>maven-war-plugin</artifactId>
                        <version>2.1.1</version>
                        <configuration>
                            <outputDirectory>webapps</outputDirectory>
                            <warName>ROOT</warName>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

我的persistance.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="testpersist">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

        <class>pl.mirkofm.model.Author</class>
        <class>pl.mirkofm.model.Played</class>
        <class>pl.mirkofm.model.Rate</class>
        <class>pl.mirkofm.model.Song</class>
     <properties>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://xx:3306/xx" />
      <property name="javax.persistence.jdbc.user" value="xx"/>
      <property name="javax.persistence.jdbc.password" value="xx"/>
    </properties>
    </persistence-unit>
</persistence>

我的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app metadata-complete="false" version="3.0"
 xmlns="http://java.sun.com/xml/ns/javaee"
 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/web-app_3_0.xsd">
 <welcome-file-list>
  <welcome-file>/index.jsp</welcome-file>
 </welcome-file-list>
</web-app>

我的应用树:

├───.openshift
│   ├───action_hooks
│   ├───config
│   ├───cron
│   │   ├───daily
│   │   ├───hourly
│   │   ├───minutely
│   │   ├───monthly
│   │   └───weekly
│   └───markers
├───.settings
├───src
│   └───main
│       ├───java
│       │   ├───META-INF
│       │   └───pl
│       │       └───mirkofm
│       │           ├───main
│       │           └───model
│       ├───resources
│       └───webapp
│           ├───images
│           └───WEB-INF
├───target
│   ├───classes
│   │   ├───META-INF
│   │   └───pl
│   │       └───mirkofm
│   │           ├───main
│   │           └───model
│   ├───m2e-wtp
│   │   └───web-resources
│   │       └───META-INF
│   │           └───maven
│   │               └───testradioapp
│   │                   └───testradioapp
│   └───test-classes
└───webapps

请帮忙。 感谢。

2 个答案:

答案 0 :(得分:1)

我正在努力解决同样的问题,发现 META-INF需要在src / main / resources 下,而不是src / main / java用于加载persistence.xml。

答案 1 :(得分:0)

您正在使用不属于类路径的EclipseLink提供程序。您需要将以下内容添加到pom.xml文件中:

<dependency>
   <groupId>org.eclipse.persistence</groupId>
   <artifactId>org.eclipse.persistence.jpa</artifactId>
   <version>2.5.1-RC3</version>
</dependency>