War 未部署缺少的持久性单元

War not deploying missing persistanceunit

我刚刚创建了一个简单的 WAR,其中包含一个简单的 JAX-RS 服务、一个无状态 EJB 和一些 JPA 实体。我正在使用 WildFly 12。

我的WAR结构如下:

我的jboss-ds.xml看起来像这样

<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<datasource jndi-name="java:/jdbc/shortbox" pool-name="mysql_pool" enabled="true" use-java-context="true">
    <connection-url>jdbc:mysql://localhost:3306/shortbox</connection-url>
    <driver>mysql</driver>
    <security>
        <user-name>admin</user-name>
        <password>admin</password>
    </security>
</datasource>
</datasources>

我的persistence.xml看起来像这样

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="shortbox-unit" transaction-type="JTA">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <jta-data-source>java:/jdbc/shortbox</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties/>
</persistence-unit>
</persistence>

我也像这样在我的 EJB 中注入了 EntityManager

@PersistenceContext(unitName = "shortbox-unit")
private EntityManager em;

我的问题是,WAR 没有像这样部署,我只是想不通为什么。 部署期间的异常如下

16:56:07,052 ERROR [org.jboss.as.server] (management-handler-thread - 1) WFLYSRV0021: Deploy of deployment "api.war" was rolled back with the following failure message: { "WFLYCTL0412: Required services that are not installed:" => [ "jboss.deployment.unit.\"api.war\".component.IssueBean.WeldInterceptorBindingsService", "jboss.deployment.unit.\"api.war\".component.IssueBean.START", "jboss.deployment.unit.\"api.war\".weld.weldClassIntrospector", "jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldInitialListener\".WeldInstantiator", "jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.ScriptFreeTLV\".WeldInstantiator", "jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldInitialListener\".START", "jboss.deployment.unit.\"api.war\".WeldStartService", "jboss.persistenceunit.\"api.war#shortbox-unit\"", "jboss.persistenceunit.\"api.war#shortbox-unit\".FIRST_PHASE", "jboss.naming.context.java.jdbc.shortbox", "jboss.deployment.unit.\"api.war\".component.IssueBean.WeldInstantiator", "jboss.deployment.unit.\"api.war\".ee.ComponentRegistry", "jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV\".WeldInstantiator", "jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.ScriptFreeTLV\".START", "jboss.naming.context.java.module.api.api.env.\"xyz.shortbox.backend.ejb.IssueBean\".em", "jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV\".START", "jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldTerminalListener\".WeldInstantiator", "jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldTerminalListener\".START", "jboss.deployment.unit.\"api.war\".component.\"javax.faces.webapp.FacetTag\".WeldInstantiator", "jboss.deployment.unit.\"api.war\".component.\"javax.faces.webapp.FacetTag\".START", "jboss.undertow.deployment.default-server.default-host./api", "jboss.undertow.deployment.default-server.default-host./api.UndertowDeploymentInfoService", "jboss.deployment.unit.\"api.war\".component.\"com.sun.faces.config.ConfigureListener\".WeldInstantiator", "jboss.deployment.unit.\"api.war\".jndiDependencyService", "jboss.deployment.unit.\"api.war\".component.\"com.sun.faces.config.ConfigureListener\".START" ], "WFLYCTL0180: Services with missing/unavailable dependencies" => [ "jboss.deployment.unit.\"api.war\".ee.ComponentRegistry is missing [jboss.deployment.unit.\"api.war\".weld.weldClassIntrospector]", "jboss.deployment.unit.\"api.war\".component.IssueBean.START is missing [jboss.naming.context.java.module.api.api.env.\"xyz.shortbox.backend.ejb.IssueBean\".em, jboss.persistenceunit.\"api.war#shortbox-unit\", jboss.deployment.unit.\"api.war\".jndiDependencyService, jboss.deployment.unit.\"api.war\".component.IssueBean.WeldInstantiator]", "jboss.deployment.unit.\"api.war\".component.IssueBean.WeldInterceptorBindingsService is missing [jboss.deployment.unit.\"api.war\".WeldStartService]", "jboss.deployment.unit.\"api.war\".weld.weldClassIntrospector is missing [jboss.deployment.unit.\"api.war\".WeldStartService]", "jboss.undertow.deployment.default-server.default-host./api.UndertowDeploymentInfoService is missing [jboss.deployment.unit.\"api.war\".WeldStartService, jboss.deployment.unit.\"api.war\".ee.ComponentRegistry]", "jboss.deployment.unit.\"api.war\".CdiValidatorFactoryService is missing [jboss.deployment.unit.\"api.war\".WeldStartService]", "jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldTerminalListener\".START is missing [jboss.deployment.unit.\"api.war\".jndiDependencyService, jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldTerminalListener\".WeldInstantiator]", "jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV\".WeldInstantiator is missing [jboss.deployment.unit.\"api.war\".WeldStartService]", "jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldInitialListener\".START is missing [jboss.deployment.unit.\"api.war\".jndiDependencyService, jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldInitialListener\".WeldInstantiator]", "jboss.deployment.unit.\"api.war\".component.\"javax.faces.webapp.FacetTag\".START is missing [jboss.persistenceunit.\"api.war#shortbox-unit\", jboss.deployment.unit.\"api.war\".component.\"javax.faces.webapp.FacetTag\".WeldInstantiator, jboss.deployment.unit.\"api.war\".jndiDependencyService]", "jboss.deployment.unit.\"api.war\".component.\"com.sun.faces.config.ConfigureListener\".WeldInstantiator is missing [jboss.deployment.unit.\"api.war\".WeldStartService]", "jboss.deployment.unit.\"api.war\".WeldStartService is missing [jboss.persistenceunit.\"api.war#shortbox-unit\", jboss.deployment.unit.\"api.war\".jndiDependencyService]", "jboss.deployment.unit.\"api.war\".component.IssueBean.WeldInstantiator is missing [jboss.deployment.unit.\"api.war\".WeldStartService, jboss.deployment.unit.\"api.war\".component.IssueBean.WeldInterceptorBindingsService]", "jboss.deployment.unit.\"api.war\".component.\"javax.faces.webapp.FacetTag\".WeldInstantiator is missing [jboss.deployment.unit.\"api.war\".WeldStartService]", "jboss.deployment.unit.\"api.war\".moduleDeploymentRuntimeInformationStart is missing [jboss.deployment.unit.\"api.war\".component.IssueBean.START]", "jboss.persistenceunit.\"api.war#shortbox-unit\".FIRST_PHASE is missing [jboss.naming.context.java.jdbc.shortbox]", "jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.ScriptFreeTLV\".START is missing [jboss.persistenceunit.\"api.war#shortbox-unit\", jboss.deployment.unit.\"api.war\".jndiDependencyService, jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.ScriptFreeTLV\".WeldInstantiator]", "jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldTerminalListener\".WeldInstantiator is missing [jboss.deployment.unit.\"api.war\".WeldStartService]", "jboss.naming.context.java.module.api.api.env.\"xyz.shortbox.backend.ejb.IssueBean\".em is missing [jboss.persistenceunit.\"api.war#shortbox-unit\"]", "jboss.undertow.deployment.default-server.default-host./api is missing [jboss.deployment.unit.\"api.war\".component.\"javax.faces.webapp.FacetTag\".START, jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldInitialListener\".START, jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldTerminalListener\".START, jboss.deployment.unit.\"api.war\".component.\"com.sun.faces.config.ConfigureListener\".START, jboss.deployment.unit.\"api.war\".WeldStartService, jboss.undertow.deployment.default-server.default-host./api.UndertowDeploymentInfoService, jboss.persistenceunit.\"api.war#shortbox-unit\", jboss.persistenceunit.\"api.war#shortbox-unit\".FIRST_PHASE, jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV\".START, jboss.deployment.unit.\"api.war\".component.IssueBean.START, jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.ScriptFreeTLV\".START]", "jboss.deployment.unit.\"api.war\".WeldEndInitService is missing [jboss.deployment.unit.\"api.war\".component.\"javax.faces.webapp.FacetTag\".START, jboss.deployment.unit.\"api.war\".WeldStartService, jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldInitialListener\".START, jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV\".START, jboss.deployment.unit.\"api.war\".component.IssueBean.START, jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldTerminalListener\".START, jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.ScriptFreeTLV\".START, jboss.deployment.unit.\"api.war\".component.\"com.sun.faces.config.ConfigureListener\".START]", "jboss.deployment.unit.\"api.war\".jndiDependencyService is missing [jboss.naming.context.java.module.api.api.env.\"xyz.shortbox.backend.ejb.IssueBean\".em]", "jboss.deployment.unit.\"api.war\".deploymentCompleteService is missing [jboss.deployment.unit.\"api.war\".component.\"javax.faces.webapp.FacetTag\".START, jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldInitialListener\".START, jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldTerminalListener\".START, jboss.undertow.deployment.default-server.default-host./api, jboss.deployment.unit.\"api.war\".component.\"com.sun.faces.config.ConfigureListener\".START, jboss.persistenceunit.\"api.war#shortbox-unit\", jboss.persistenceunit.\"api.war#shortbox-unit\".FIRST_PHASE, jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV\".START, jboss.deployment.unit.\"api.war\".component.IssueBean.START, jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.ScriptFreeTLV\".START]", "jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.ScriptFreeTLV\".WeldInstantiator is missing [jboss.deployment.unit.\"api.war\".WeldStartService]", "jboss.deployment.unit.\"api.war\".component.\"com.sun.faces.config.ConfigureListener\".START is missing [jboss.persistenceunit.\"api.war#shortbox-unit\", jboss.deployment.unit.\"api.war\".component.\"com.sun.faces.config.ConfigureListener\".WeldInstantiator, jboss.deployment.unit.\"api.war\".jndiDependencyService]", "jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV\".START is missing [jboss.persistenceunit.\"api.war#shortbox-unit\", jboss.deployment.unit.\"api.war\".jndiDependencyService, jboss.deployment.unit.\"api.war\".component.\"javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV\".WeldInstantiator]", "jboss.persistenceunit.\"api.war#shortbox-unit\" is missing [jboss.naming.context.java.jdbc.shortbox, jboss.persistenceunit.\"api.war#shortbox-unit\".FIRST_PHASE]", "jboss.deployment.unit.\"api.war\".component.\"org.jboss.weld.module.web.servlet.WeldInitialListener\".WeldInstantiator is missing [jboss.deployment.unit.\"api.war\".WeldStartService]" ] }

当我删除 jboss-ds.xml 并配置 persistence.xml 以使用我的数据库时,一切都在正常部署 - 但应用程序正在使用 exampleDS,因为我还没有配置任何其他DS。 我做错了什么?

还有一个重要的注意事项 - 我绝对想在我的 Appliaction 中管理 DS,而不是在 JBoss 配置中。

提前致谢!

解决方案就像 ABC 一样简单...jboss.xml 必须放在 WEB-INF 根目录中,而不是 META-INF。