Java 生产EntityManager抛出第一阶段缺失

Java 生产EntityManager抛出第一阶段缺失,java,hibernate,persistence.xml,wildfly,Java,Hibernate,Persistence.xml,Wildfly,这是我的错误 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 2) JBAS014613: Operation ("deploy") failed - address: ([("deployment" => "test.war")]) - failure description: {"JBAS014771: Services with missing/unavailable

这是我的错误

ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 2) JBAS014613: Operation ("deploy") failed - address: ([("deployment" => "test.war")]) - failure description: {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.persistenceunit.\"test.war#primary\".__FIRST_PHASE__ is missing [jboss.naming.context.java.jboss.datasources.KitchensinkQuickstartTestDS]"]}                                                                                                       
ERROR [org.jboss.as.server] (management-handler-thread - 2) JBAS015870: Deploy of deployment "test.war" was rolled back with the following failure message: {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.persistenceunit.\"test.war#primary\".__FIRST_PHASE__ is missing [jboss.naming.context.java.jboss.datasources.KitchensinkQuickstartTestDS]"]}  
以及堆栈跟踪的一部分导致的错误

Caused by: java.lang.Exception: "JBAS014807: Management resource '[(\"deployment\" => \"test.war\")]' not found"
    at org.jboss.as.controller.client.helpers.standalone.impl.ServerDeploymentPlanResultFuture.getActionResult(ServerDeploymentPlanResultFuture.java:134) ~[wildfly-controller-client-8.0.0.Final.jar:8.0.0.Final]
    at org.jboss.as.controller.client.helpers.standalone.impl.ServerDeploymentPlanResultFuture.getResultFromNode(ServerDeploymentPlanResultFuture.java:123) ~[wildfly-controller-client-8.0.0.Final.jar:8.0.0.Final]
    at org.jboss.as.controller.client.helpers.standalone.impl.ServerDeploymentPlanResultFuture.get(ServerDeploymentPlanResultFuture.java:85) ~[wildfly-controller-client-8.0.0.Final.jar:8.0.0.Final]
    at org.jboss.as.controller.client.helpers.standalone.impl.ServerDeploymentPlanResultFuture.get(ServerDeploymentPlanResultFuture.java:42) ~[wildfly-controller-client-8.0.0.Final.jar:8.0.0.Final]
以及相关的日志输出

2014-03-25 00:06:26,543 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 3) JBAS014613: Operation ("deploy") failed - address: ([("deployment" => "test.war")]) - failure description: {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.persistenceunit.\"test.war#primary\".__FIRST_PHASE__ is missing [jboss.naming.context.java.jboss.datasources.KitchensinkQuickstartTestDS]"]}
2014-03-25 00:06:26,544 ERROR [org.jboss.as.server] (management-handler-thread - 3) JBAS015870: Deploy of deployment "test.war" was rolled back with the following failure message: {"JBAS014771: Services with missing/unavailable dependencies" => jboss.persistenceunit.\"test.war#primary\".__FIRST_PHASE__ is missing [jboss.naming.context.java.jboss.datasources.KitchensinkQuickstartTestDS]"]}
2014-03-25 00:06:26,551 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-8) JBAS015877: Stopped deployment test.war (runtime-name: test.war) in 7ms
2014-03-25 00:06:26,552 INFO  [org.jboss.as.controller] (management-handler-thread - 3) JBAS014774: Service status report
JBAS014775:    New missing/unsatisfied dependencies:
      service jboss.naming.context.java.jboss.datasources.KitchensinkQuickstartTestDS (missing) dependents: [service jboss.persistenceunit."test.war#primary".__FIRST_PHASE__]
      service jboss.persistenceunit."test.war#primary".__FIRST_PHASE__ (missing) dependents: [service jboss.deployment.unit."test.war".POST_MODULE]

2014-03-25 00:06:26,558 DEBUG [org.jboss.as.controller.management-operation] (management-handler-thread - 4) JBAS014616: Operation ("undeploy") failed - address: ([("deployment" => "test.war")]) - failure description: "JBAS014807: Management resource '[(\"deployment\" => \"test.war\")]' not found"
2014-03-25 00:06:26,586 DEBUG [org.jboss.as.controller.management-operation] (management-handler-thread - 2) Entered VERIFY stage; waiting for service container to settle
2014-03-25 00:06:26,595 INFO  [org.jboss.as.controller] (management-handler-thread - 2) JBAS014774: Service status report
JBAS014776:    Newly corrected services:
      service jboss.naming.context.java.jboss.datasources.KitchensinkQuickstartTestDS (no longer required)
      service jboss.persistenceunit."test.war#primary".__FIRST_PHASE__ (no longer required)
这是我罐子里的东西

ar = 64668e4f-f815-495a-a612-bc1c9c87b4cc.jar:
/com/
/com/lm/
/com/lm/infrastructure/
/com/lm/infrastructure/Regex.class
/com/lm/infrastructure/SystemServices.class
/com/lm/infrastructure/RegexTest.class
/com/lm/infrastructure/JacksonProducer.class
/com/lm/model/
/com/lm/model/Identifiable.class
/com/lm/model/Page.class
/com/lm/model/Entity.class
/com/lm/model/Buildable.class
/com/lm/model/Wirer.class
/com/lm/model/BaseIdentifierDTO.class
/com/lm/model/Factory.class
/com/lm/model/EntityBuilder.class
/com/lm/model/Director.class
/com/lm/model/Builder.class
/com/lm/model/Identifier.class
/com/lm/model/Repository.class
/com/lm/test/
/com/lm/test/TestBase.class
/com/lm/test/UnitTest.class
/com/lm/test/RESTCtrlTestBase.class
/com/lm/test/TestUtil.class
/com/lm/activity/
/com/lm/activity/persistence/
/com/lm/activity/persistence/inmemory/
/com/lm/activity/persistence/inmemory/ActivityInventoryMemUnitTest.class
/com/lm/activity/persistence/inmemory/ActivitiesMemUnitTest.class
/com/lm/activity/persistence/inmemory/ActivityInventoryMem.class
/com/lm/activity/persistence/inmemory/ActivitiesMem.class
/com/lm/activity/UnitTestBaseForActivity.class
/com/lm/activity/SimplyDescriptive.class
/com/lm/activity/Activity$Builder.class
/com/lm/activity/ActivityId.class
/com/lm/activity/ActivitiesRepo.class
/com/lm/activity/FactoryBuilderActivity.class
/com/lm/activity/ActivityInventory.class
/com/lm/activity/Activity$DTO.class
/com/lm/activity/Activity.class
/com/lm/activity/ActivityCompleted.class
/com/lm/activity/Activity_.class
/com/lm/activity/ActivityId$DTO.class
/com/lm/activity/ToDoUnitTest.class
/com/lm/activity/ActivityUnitTest.class
/com/lm/activity/TestBaseForActivity.class
/com/lm/activity/ActivityEvent.class
/com/lm/activity/BuilderActivityPermaURI.class
/com/lm/activity/Descriptive.class
/com/lm/activity/ToDo.class
/com/lm/activity/DomainEvent.class
/com/lm/activity/Individual.class
/META-INF/
/META-INF/logback.xml
/META-INF/test-ds.xml
/META-INF/beans.xml
/META-INF/persistence.xml
这是我的
persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence 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"
             version="2.1">
<persistence-unit name="primary">
    <jta-data-source>java:jboss/datasources/KitchensinkQuickstartTestDS</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
        <!-- Properties for Hibernate -->
        <property name="hibernate.hbm2ddl.auto" value="create-drop" />
        <property name="hibernate.show_sql" value="false" />
    </properties>
</persistence-unit>
</persistence>
<?xml version="1.0" encoding="UTF-8"?>
<!-- This is an unmanaged datasource. It should be used for proofs of concept 
   or testing only. It uses H2, an in memory database that ships with JBoss 
   AS. -->
<datasources xmlns="http://www.jboss.org/ironjacamar/schema"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
   <!-- The datasource is bound into JNDI at this location. We reference 
      this in META-INF/test-persistence.xml -->
   <datasource jndi-name="java:jboss/datasources/KitchensinkQuickstartTestDS"
      pool-name="kitchensink-quickstart-test" enabled="true"
      use-java-context="true">
       <connection-url>jdbc:h2:mem:kitchensink-quickstart-test</connection-url>
      <driver>h2</driver>
      <security>
         <user-name>sa</user-name>
         <password>sa</password>
      </security>
   </datasource>
</datasources>
SystemServices
class

public class SystemServices {

    @SuppressWarnings( "unused" )
    @Produces
    @PersistenceContext
    private EntityManager em;

    @Produces
    public Logger prLogger( InjectionPoint ip ) {
        return LoggerFactory.getLogger(
                ip.getMember().getDeclaringClass().getName()
        );
    }
}

我还没有任何实体具有任何注释,因此我认为它应该能够生成
EntityManager
,而不会引起问题。

错误表明jboss缺少您的数据源。您使用的是哪个JBoss/Wildfly版本

请首先检查JBoss是否可以使用f.i.web控制台(localhost:9090/console->Profile->Datasources)处理您的数据源

您也可以在standalone.xml中配置数据源,但这是否合适取决于您的设置,但我更喜欢standalone.xml方法


我认为*-ds.xml数据源配置文件必须单独部署,而不是与jar一起部署。请查看数据源配置。我认为这可能会导致您的问题,因为JBoss在部署数据源定义之前解析persistence.xml,并且在持久性管理器初始化时失败。

wildfly 8 CR1(final中有一个bug阻止我使用它)。kitchensink应用程序似乎建议可以将数据源作为jar的一部分进行部署?(现在阅读文档)“从WildFly 8开始,您可以部署-ds.xml文件”,如果您在web控制台(localhost:9090/console->Profile->Datasources)中配置数据源,但忘记单击“Enable”,同样的错误也会发生。