java没有名为wspersist的EntityManager的持久性提供程序
我正在构建一个JAX-RS web服务(Jersey),现在我正尝试开始使用JPA。我选择了eclipselink来管理这种持久性
首先,我正在编写一些junit测试用例,直到我弄清楚所有东西是如何结合在一起的
在我的坚持中。xml(WEB-INF/persistence.xml)我有:
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="ws-persist" transaction-type="RESOURCE_LOCAL">
<class>beans.Change</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3333/tomcat" />
<property name="javax.persistence.jdbc.user" value="tomcat" />
<property name="javax.persistence.jdbc.password" value="...." />
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
</properties>
</persistence-unit>
在我的测试课上我有
public class PersistenceTests {
private EntityManager em = null;
@Before
public void setUp() throws Exception {
Properties propertiesMap = new Properties();
propertiesMap.put(PersistenceUnitProperties.DDL_GENERATION, PersistenceUnitProperties.DROP_AND_CREATE);
EntityManagerFactory factory = Persistence.createEntityManagerFactory("ws-persist", propertiesMap);
em = factory.createEntityManager();
}
@After
public void tearDown() throws Exception {
}
@Test
public void testSetUp(){
Assert.assertNotNull("Entity manager was null", em);
Assert.assertTrue("Entity manager wasn't connected", em.isOpen());
}
}
我有日食。jar和两个javax。持久性*。我的WEB-INF/lib文件夹下的JAR。 我在标题中遇到了一个异常,有人能帮我解决这个问题吗
谢谢
# 1 楼答案
我将尝试在持久性中添加持久性提供程序。xml
(编辑)或移动持久性。xml到
META-INF
文件夹。对于web应用程序,这必须在WEB-INF/classes