更新:我已经解决了这个问题,将jar逐个添加到类路径并进行调试。我有两个相互对峙的罐子。这些罐子与REST有关。
当我尝试启动webapp时,我收到此异常:
javax.persistence.PersistenceException: No Persistence provider for EntityManager named fooBar
我正在使用REST和Hibernate,我有以下持久性xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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"
version="2.1">
<persistence-unit name="fooBar" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>whateverpackage.Users</class>
<class>whateverpackage.Messages</class>
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<properties>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/Test2?createDatabaseIfNotExist=true" />
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.connection.password" value="password" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.use_sql_comments" value="true" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory" />
</properties>
</persistence-unit>
我正在使用最新的Jersey和Hibernate,它们被添加到类路径中。包含persistence.xml的META-INF文件夹位于项目的src文件夹中。
我在类路径中有以下jar: