以下是我persistence.xml
的样子
<?xml version="1.0" encoding="UTF-8"?>
<persistence
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/persistence"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="earth">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:/jdbc/EarthDS</jta-data-source>
<properties>
<property name="hibernate.archive.autodetection" value="class"/>
<property name="hibernate.id.new_generator_mappings" value="true"/>
<property name="javax.persistence.lock.timeout" value="5000"/>
</properties>
</persistence-unit>
</persistence>
我正在使用war
部署maven-cargo-plugin
文件。根据他们的documentation,他们将数据源设置为JNDI
为
<configuration>
<properties>
<cargo.datasource.datasource.derby>
cargo.datasource.driver=org.apache.derby.jdbc.EmbeddedDriver|
cargo.datasource.url=jdbc:derby:derbyDB;create=true|
cargo.datasource.jndi=jdbc/CargoDS|
cargo.datasource.username=APP|
cargo.datasource.password=nonemptypassword
</cargo.datasource.datasource.derby>
</properties>
</configuration>
由于我使用H2
数据库,我将其设置为
<properties>
<cargo.servlet.port>9090</cargo.servlet.port>
<properties>
<cargo.datasource.datasource>
cargo.datasource.driver=org.h2.Driver|
cargo.datasource.url=jdbc:h2:~/earth;create=true|
cargo.datasource.jndi=jdbc/EarthDS|
cargo.datasource.username=sa|
cargo.datasource.password=
</cargo.datasource.datasource>
</properties>
</properties>
</configuration>
当我运行项目时,我在日志中看到错误为
[INFO] [talledLocalContainer] 09:43:01,335 INFO [org.jboss.as.server.deployment] (MSC service thread 1-12) JBAS015876: Starting deployment of "cargocpc.war" (runtime-name: "cargocpc.war")
[INFO] [talledLocalContainer] 09:43:01,335 INFO [org.jboss.as.server.deployment] (MSC service thread 1-11) JBAS015876: Starting deployment of "earth.war" (runtime-name: "earth.war")
[INFO] [talledLocalContainer] 09:43:01,478 INFO [org.jboss.ws.common.management] (MSC service thread 1-3) JBWS022052: Starting JBoss Web Services - Stack CXF Server 4.2.3.Final
[INFO] [talledLocalContainer] 09:43:01,753 INFO [org.wildfly.extension.undertow] (MSC service thread 1-6) JBAS017534: Registered web context: /cargocpc
[INFO] [talledLocalContainer] 09:43:01,779 INFO [org.jboss.as.jpa] (MSC service thread 1-16) JBAS011401: Read persistence.xml for earth
[INFO] [talledLocalContainer] WildFly 8.x started on port [9090]
[INFO]
[INFO] --- cargo-maven2-plugin:1.4.8:stop (stop-container) @ integration ---
[INFO] [talledLocalContainer] 09:43:01,865 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014613: Operation ("deploy") failed - address: ([("deployment" => "earth.war")]) - failure description: {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.persistenceunit.\"earth.war#earth\".__FIRST_PHASE__ is missing [jboss.naming.context.java.jdbc.EarthDS]"]}
[INFO] [talledLocalContainer] 09:43:01,898 INFO [org.jboss.as.server] (ServerService Thread Pool -- 29) JBAS018559: Deployed "earth.war" (runtime-name : "earth.war")
[INFO] [talledLocalContainer] 09:43:01,898 INFO [org.jboss.as.server] (ServerService Thread Pool -- 29) JBAS018559: Deployed "cargocpc.war" (runtime-name : "cargocpc.war")
[INFO] [talledLocalContainer] 09:43:01,899 INFO [org.jboss.as.controller] (Controller Boot Thread) JBAS014774: Service status report
[INFO] [talledLocalContainer] JBAS014775: New missing/unsatisfied dependencies:
[INFO] [talledLocalContainer] service jboss.naming.context.java.jdbc.EarthDS (missing) dependents: [service jboss.persistenceunit."earth.war#earth".__FIRST_PHASE__]
[INFO] [talledLocalContainer]
[INFO] [talledLocalContainer] 09:43:01,908 INFO [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management
[INFO] [talledLocalContainer] 09:43:01,909 INFO [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990
[INFO] [talledLocalContainer] 09:43:01,909 ERROR [org.jboss.as] (Controller Boot Thread) JBAS015875: WildFly 8.0.0.Final "WildFly" started (with errors) in 2415ms - Started 262 of 318 services (2 services failed or missing dependencies, 92 services are lazy, passive or on-demand)
[INFO] [talledLocalContainer] WildFly 8.x is stopping...
[INFO] [talledLocalContainer] 09:43:02,137 INFO [org.jboss.as.server.deployment] (MSC service thread 1-8) JBAS015877: Stopped deployment earth.war (runtime-name: earth.war) in 14ms
[INFO] [talledLocalContainer] 09:43:02,185 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018558: Undeployed "earth.war" (runtime-name: "earth.war")
[INFO] [talledLocalContainer] 09:43:02,186 INFO [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report
[INFO] [talledLocalContainer] JBAS014775: New missing/unsatisfied dependencies:
[INFO] [talledLocalContainer] service jboss.persistenceunit."earth.war#earth".__FIRST_PHASE__ (missing) dependents: [service jboss.deployment.unit."earth.war".POST_MODULE]
[INFO] [talledLocalContainer]
[INFO] [talledLocalContainer] INFO [org.jboss.modules] JBoss Modules version 1.3.0.Final
[WARNING] [talledLocalContainer] WARN: can't find jboss-cli.xml. Using default configuration values.
[INFO] [talledLocalContainer] INFO [org.xnio] XNIO version 3.2.0.Final
[INFO] [talledLocalContainer] INFO [org.xnio.nio] XNIO NIO Implementation Version 3.2.0.Final
[INFO] [talledLocalContainer] INFO [org.jboss.remoting] JBoss Remoting version 4.0.0.Final
[INFO] [talledLocalContainer] 09:43:02,806 INFO [org.jboss.as.controller] (management-handler-thread - 3) JBAS014774: Service status report
[INFO] [talledLocalContainer] JBAS014776: Newly corrected services:
[INFO] [talledLocalContainer] service jboss.naming.context.java.jdbc.EarthDS (no longer required)
[INFO] [talledLocalContainer] service jboss.persistenceunit."earth.war#earth".__FIRST_PHASE__ (no longer required)
[INFO] [talledLocalContainer]
[INFO] [talledLocalContainer] INFO [org.jboss.as.cli.CommandContext] {"outcome" => "success"}
[INFO] [talledLocalContainer] {"outcome" => "success"}
[INFO] [talledLocalContainer] 09:43:02,813 INFO [org.wildfly.extension.undertow] (MSC service thread 1-10) JBAS017535: Unregistered web context: /cargocpc
有人可以帮我理解这里不正确的事吗?
由于
答案 0 :(得分:0)
在doc片段中,名称有4个部分 在你的例子中,它只有3部分
由于货物可以配置多个数据源,第4部分是否需要唯一识别它们?
答案 1 :(得分:0)
使用与persistence.xml中相同的jndi字符串,并在jdbc字符串中指定file或mem:
<cargo.datasource.datasource.h2>
cargo.datasource.jndi=java:/jdbc/EarthDS|
cargo.datasource.driver=org.h2.Driver|
cargo.datasource.url=jdbc:h2:mem:earth;create=true|
cargo.datasource.username=sa|
cargo.datasource.password=sa
</cargo.datasource.datasource.h2>
确保容器具有h2驱动程序的依赖关系:
<container>
...
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
</dependencies>
</container>
并且h2驱动程序列在maven依赖项中:
<dependencies>
...
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.182</version>
</dependency>
</dependencies>