javax.persistence.persistenceexception:没有名为zaapmartpu的entitymanager的持久性提供程序

wn9m85ua  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(244)

我已经使用EclipselinkJPA2.1一年了。我知道这个问题以前有人问过,我见过这个,这个,这个,还有这个。
我在jdk8、tomcat8和eclipselinkjpa2.1上运行了一年多。jpa的一切都很顺利。我们决定转移到运行在Tomcat9上的JDK11服务器上。我遇到了一些错误,决定将我的ecliselink jpa库更新到ecliselink 3.0.0
现在我在一个顺利运行了一年多的jpa项目上遇到了这个错误:

16-Dec-2020 10:23:45.111 SEVERE [main] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class [admin.zaapmart.ContextListener]
javax.persistence.PersistenceException: No Persistence provider for EntityManager named ZaapMartPU
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
at admin.zaapmart.ContextListener.loadRemoteEntityManagerFactory(ContextListener.java:192)
at admin.zaapmart.ContextListener.contextInitialized(ContextListener.java:120)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4668)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5136)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:713)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:695)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:631)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1832)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:118)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:526)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:425)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1577)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:309)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:424)
at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:367)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:929)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:831)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1377)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1367)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:902)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:423)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:928)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.startup.Catalina.start(Catalina.java:638)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:350)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:492)

引发此错误的webapplicationlistener类:

/**
 * Web application lifecycle listener.
 *
 * @author Jevison7x
 */
public class ContextListener implements ServletContextListener
{
    ...

    @Override
    public void contextInitialized(ServletContextEvent sce)
    {
        ...
        this.loadRemoteEntityManagerFactory();
        ...
    }

    private void loadRemoteEntityManagerFactory()
    {
        Map<String, String> persistenceMap = new HashMap<>();
        persistenceMap.put("javax.persistence.jdbc.url", remoteDBProperties.getProperty("zaapmart_db.url"));
        persistenceMap.put("javax.persistence.jdbc.user", remoteDBProperties.getProperty("db.user"));
        persistenceMap.put("javax.persistence.jdbc.password", remoteDBProperties.getProperty("db.pass"));
        persistenceMap.put("javax.persistence.jdbc.driver", remoteDBProperties.getProperty("driverName"));
        //Next line throws the Error
        DBConfiguration.remoteEntityManagerFactory = Persistence.createEntityManagerFactory("ZaapMartPU", persistenceMap);
    }
...

这是我的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="ZaapMartPU" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <class>com.zaapmart.purchases.Transaction</class>
        <class>com.zaapmart.products.Category</class>
        <class>com.zaapmart.products.Product</class>
        <class>com.zaapmart.products.ProductImage</class>
        <class>com.zaapmart.products.SubCategory</class>
        <class>com.zaapmart.purchases.OrderItem</class>
        <class>com.zaapmart.users.User</class>
        <class>com.zaapmart.users.Supplier</class>
        <class>com.zaapmart.wallet.Voucher</class>
        <class>com.zaapmart.purchases.TransactionHistory</class>
        <class>com.zaapmart.wallet.VirtualWallet</class>
        <class>com.zaapmart.wallet.WalletPOP</class>
        <class>com.zaapmart.wallet.WalletTransaction</class>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/xxx_zaapmart"/>
            <property name="javax.persistence.jdbc.user" value="bahaushi_zaapapp"/>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
            <property name="javax.persistence.jdbc.password" value="xxxxxxx"/>
        </properties>
    </persistence-unit>
</persistence>

我认为persistence.xml位于正确的位置:

以下是我的库列表:

eclipselink 3.0.0类路径:

我从这里下载了eclipslink。
有人能告诉我这里怎么了吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题