我使用maven原型创建了Struts 2 web app
。现在,当我在tomcat7
上部署该项目并编辑persistence.xml
来更改数据库配置时,它没有反映在Application中。为了测试我的理论,我从persistence.xml
中删除了WEB-INF/classes/META-INF/
。即便如此,我得到的是: -
Connection refused: connect
java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect.
java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect.
Internal Exception: java.sql.SQLNonTransientConnectionException: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect. Error Code: 40000
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLNonTransientConnectionException: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused: connect. Error Code: 40000
我不知道从哪个位置获取持久性配置。这是我的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="em" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.ankitsoft.entities.City</class>
<class>com.ankitsoft.entities.Country</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:derby:C:\proLoc\WEB-INF\DB"/>
<property name="javax.persistence.jdbc.password" value="ankit"/>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver"/>
<property name="javax.persistence.jdbc.user" value="ankit"/>
</properties>
</persistence-unit>
</persistence>
有人可以帮助我吗?
答案 0 :(得分:0)
如果你在一个bundle中调用persistence.xml,那么org.eclipse.persistence.jpa必须在你的bundle(或多个bundle)之前启动。因此,始终将 org.eclipse.persistence 添加为清单中的导入包是个好主意