gpt4 book ai didi

java - Openshift - EntityManager 没有持久性提供程序

转载 作者:行者123 更新时间:2023-11-30 11:28:11 25 4
gpt4 key购买 nike

我在将我的应用程序部署到 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>

我的持久化.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

请帮忙。谢谢。

最佳答案

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

关于java - Openshift - EntityManager 没有持久性提供程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18973545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com