我一直试图让我的JPA(openJPA)应用程序使用非jta数据源与Tomcat一起工作。
我正在使用maven而没有IDE。只是vi在windows上,主要是为了了解事情是如何工作的并且聚集在一起
这是我得到的错误(我已经在SO上研究了类似的问题但无法找到修复程序)
Caused by: java.lang.RuntimeException: <openjpa-2.3.0-r422266:1540826 fatal user error> org.apache.openjpa.persistence.ArgumentException: The persistence provider is attempting to use properties in the persistence.xml file to resolve the data source. A Java Database Connectivity (JDBC) driver or data source class name must be specified in the openjpa.ConnectionDriverName or javax.persistence.jdbc.driver property. The following properties are available in the configuration: "org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl@442ce698".
这是我的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="CricketScorer" transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<non-jta-data-source>java:/comp/env/jdbc/scoringdb</non-jta-data-source>
<class>com.mantr.cricket.scorer.server.persistence.entities.Account</class>
<class>com.mantr.cricket.scorer.server.persistence.entities.Delivery</class>
<class>com.mantr.cricket.scorer.server.persistence.entities.DeliveryPK</class>
<class>com.mantr.cricket.scorer.server.persistence.entities.Match</class>
<class>com.mantr.cricket.scorer.server.persistence.entities.Player</class>
<class>com.mantr.cricket.scorer.server.persistence.entities.Team</class>
</persistence-unit>
</persistence>
这是Tomcat的context.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<!-- JDBC Data source for the scoring database -->
<Resource name="jdbc/scoringdb"
auth="Container"
type="javax.sql.DataSource"
username="b888446f2789ce"
password="28fa221e"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://us-cdbr-east-06.cleardb.net/heroku_17744ef452a6a8d"
maxActive="10"
maxIdle="4"/>
</Context>
Web.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>cxf</servlet-name>
<display-name>cxf</display-name>
<description>Apache CXF Endpoint</description>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<resource-ref>
<description>Scoring Database</description>
<res-ref-name>jdbc/scoringdb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
当我尝试使用JNDI初始上下文打开连接时,这是有效的。所以JNDI数据源配置正确,我认为
答案 0 :(得分:0)
请参阅我的Tomcat webapp的个人自动管理OpenJPA2.x包装器。查看jdbc名称,你可能会有一个额外的“/”字符? https://github.com/Murmur/ScopedEntityManager/blob/master/example_webapp/webapp/WEB-INF/classes/META-INF/persistence.xml
<non-jta-data-source>java:/comp/env/jdbc/scoringdb</non-jta-data-source>
<non-jta-data-source>java:comp/env/jdbc/test</non-jta-data-source>