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

Why does my Java app work in local but when delivering to IBM Cloud it gives this error

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

当我在本地 运行 应用程序时,我能够使用 curl 查询我的服务器并获得所有 GET 和 POST 请求的正确响应。但是,当我在 IBM Cloud 上托管服务器并使用 curl 对其进行查询时,出现错误:"No Persistence provider for 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

manifest.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)

链接的搜索的第一个结果的评论中找到我的解决方案