gpt4 book ai didi

java - 为什么我的 Java 应用程序可以在本地运行,但在交付到 IBM Cloud 时却出现此错误

转载 作者:行者123 更新时间:2023-12-02 10:11:44 25 4
gpt4 key购买 nike

我创建了一个使用 JPA 以及带有 JAX-RS 的 servlet 的应用程序。

当我在本地运行应用程序时,我可以使用curl 查询我的服务器并获得所有 GET 和 POST 请求的正确响应。但是,当我在 IBM Cloud 上托管服务器并使用curl 查询它时,我收到错误:“没有 EntityManager 的持久性提供程序”。

是什么导致本地和远程 (IBM Cloud) 环境之间存在差异?我可以采取哪些措施来解决该问题?

<小时/>

persistence.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="ibmcloud">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<non-jta-data-source>java:comp/DefaultDataSource</non-jta-data-source>
<class>entities.Comment</class>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.use_sql_comments" value="true"/>

</properties>
</persistence-unit>
</persistence>

.travis.yml

language: java
jdk: oraclejdk8
sudo: false
before_install:
mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
before_deply:
cf login -u $BLUEMIX_USER -o $BLUEMIX_ORG
script:
mvn test -B
language: java
git:
depth: 1
dist: trusty
cache:
directories:
- "$HOME/.m2"
deploy:
edge: true
provider: bluemixcloudfoundry
username: $BLUEMIX_USER
password: $BLUEMIX_PASSWORD
organization: $BLUEMIX_ORG
space: $BLUEMIX_SPACE
manifest: manifest.yml
app_name: ibmcloudapp
region: eu-gb
api: https://api.eu-gb.bluemix.net
skip_cleanup: true

ma​​nifest.yml

applications:
- name: ibmcloud
path: target/ibmcloud.war
instances: 1
random-route: true

pom.xml

<?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>com.dotheminimum</groupId>
<artifactId>ibmcloud</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>

<dependencies>
<!-- https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate.javax.persistence/hibernate-jpa-2.1-api -->
<!-- <dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.2.Final</version>
</dependency> -->
<!-- https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api -->
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
</plugins>
</build>
</project>

该应用程序的源代码托管here

最佳答案

问题是我的“persistence.xml”文件位于“src/main/java/META-INF”而不是“src/main/resources/META-INF”下。

我的本​​地环境能够找到该文件,但 IBM Cloud 却找不到。更改“persistence.xml”的路径后,IBM Cloud 检测到该文件。

如果我详尽无遗,我就能在 Billy Frost ( No Persistence provider for EntityManager named ) 链接的第一个搜索结果的评论中找到我的解决方案

关于java - 为什么我的 Java 应用程序可以在本地运行,但在交付到 IBM Cloud 时却出现此错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54959422/

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