为什么我的Java应用程序在本地工作,但在交付给IBM Cloud时会出现此错误

问题描述 投票:0回答:1

我创建了一个使用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

manifest.yml

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

pom.hml

<?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

java jpa ibm-cloud persistence.xml
1个回答
1
投票

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

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

如果我已经详尽无遗,我本可以在比利弗罗斯特(No Persistence provider for EntityManager named)链接的搜索的第一个结果的评论中找到我的解决方案。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.