【发布时间】:2014-10-13 08:40:20
【问题描述】:
我正在使用JPA 2.1、EclipseLink 2.5、Struts 1.3 在Eclipse Kepler 上做一个项目,并部署在Tomcat 7.0 上。我创建了一个名为JPADataSource 的项目。在这些条件下,我的项目运行良好。虽然,当我将 DataSources (MySQL) 添加到项目中时,它不再起作用。当我尝试运行代码时,出现此错误:
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'jdbc:mysql://localhost:3306/playlist?autoReconnect=true'
我在我的代码中设置了所有内容。这是我的context.xml(放在/JPADataSource/WebContent/META-INF/):
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/JPADataSource">
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<ResourceLink
global="jdbc/playlist"
name="jdbc/playlist"
type="javax.sql.DataSource">
</ResourceLink>
</Context>
这是我的persistance.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="JPADataSource" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<non-jta-data-source>java:comp/env/jdbc/playlist</non-jta-data-source>
<class>model.Singer</class>
<class>model.Song</class>
<class>model.User</class>
<class>model.UserPlaylist</class>
</persistence-unit>
</persistence>
最后,这是我在server.xml 中的<GlobalNamingResources> 下插入的内容(放置在localhost-config/ 的/Server/Tomcat v7.0 服务器中):
<Resource auth="Container" driverClass="com.mysql.jdbc.Driver" maxActive="100" maxIdle="30" maxWait="10000" name="jdbc/playlist" password="root" type="javax.sql.DataSource" url="jdbc:mysql://localhost:3306/playlist?autoReconnect=true" username="root"/>
我做错了什么?或者,我遗漏了什么/放错地方了?
感谢任何帮助。
【问题讨论】:
-
对不起,是我。我将删除 dup。我的问题还在。
标签: java tomcat jpa datasource