【问题标题】:How to create JBoss EAR project with JPA, EJB and CDI elements如何使用 JPA、EJB 和 CDI 元素创建 JBoss EAR 项目
【发布时间】:2015-06-13 23:41:24
【问题描述】:

我正在尝试使用 EJB、JPA 和 Web 元素创建 EAR 项目。 我已经连接到数据库并认为它工作正常。但我无法从 EJB 项目中 @inject bean。

这是我的配置: 在 EAR 项目 EarContent/META-INF/application.xml 中:

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_7.xsd" id="Application_ID" version="7">
  <display-name>Fantasy</display-name>
  <module>
    <ejb>FantasyEjb.jar</ejb>
  </module>
  <module>
    <web>
      <web-uri>FantasyWeb.war</web-uri>
      <context-root>FantasyWeb</context-root>
    </web>
  </module>
</application>

在EAR项目EarContent/WEB-INF/jboss-deployment-structure.xml中:

<?xml version="1.0"?>
<jboss-deployment-structure>
   <deployment>
        <exclusions>
          <module name="javax.faces.api" />
          <module name="com.sun.jsf-impl" />
        </exclusions>
        <dependencies>
          <module name="org.apache.log4j" />
          <module name="org.dom4j" />
          <module name="org.apache.commons.logging" />
          <module name="org.apache.commons.collections" />
          <module name="javax.faces.api" />
          <module name="com.sun.jsf-impl" />
        </dependencies>
    </deployment>
</jboss-deployment-structure>

在JPA项目文件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="JPADB">
        <jta-data-source>java:jboss/datasources/AGHDS</jta-data-source>
        <properties>
            <property name="showSql" value="true"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
            <property name="hibernate.hbm2ddl.auto" value="create-drop" />
        </properties>
    </persistence-unit>
</persistence>

在EJB项目ejbModule/META-INF/ejb-jar.xml中

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar version="3.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/ejb-jar_3_2.xsd">
    <display-name>FantasyEjb</display-name>
</ejb-jar>

在WEB项目WebContent/WEB-INF/beans.xml中:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
    bean-discovery-mode="all">
</beans>

现在我在 EJB 项目 TestBean.java 中有一个 bean:

package com.fantasy.beans;

import java.io.Serializable;
import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.fantasy.db.model.Elfs;

@Stateless
public class TestBean implements Serializable{

    private static final long serialVersionUID = 1L;

    @PersistenceContext(unitName = "JPADB")
    private EntityManager em;

    public List<Elfs> query() {
        Query query = em.createQuery("FROM com.fantasy.db.model.Elfs");

        @SuppressWarnings("unchecked")
        List <Elfs> list =  query.getResultList();
        return list; 
    }
}

在 WEB 项目中,我有类 Producer.java 想在 JSF 页面中使用:

package com.fantasy.web;

import java.io.Serializable;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.inject.Named;

import com.fantasy.beans.TestBean;
import com.fantasy.db.model.Elfs;

@Named(value = "blogEntryBean")
@RequestScoped
public class Producer implements Serializable {

    private static final long serialVersionUID = 1L;

    @Inject
    TestBean bean;

    private List<Elfs> beans;

    @Produces
    @Named
    public List<Elfs> getBeans() {
        return beans;
    }

    public void setBeans(List<Elfs> beans) {
        this.beans = beans;
    }

    @PostConstruct
    public void retrieveAllSeatsOrderedByName() {
        beans = bean.query();


    }
}

问题在于注解@inject。没有它不会显示错误 - 但我需要将它与我的 ejb 同步。我想我可能会遗漏一些依赖项,但我不知道如何修复它。

日志:

01:14:02,294 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 50) HHH000227: Running hbm2ddl schema export
01:14:02,390 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 50) HHH000230: Schema export complete
01:14:03,033 SEVERE [javax.enterprise.resource.webcontainer.jsf.flow] (MSC service thread 1-3) Unable to obtain CDI 1.1 utilities for Mojarra
01:14:03,044 SEVERE [javax.enterprise.resource.webcontainer.jsf.application.view] (MSC service thread 1-3) Unable to obtain CDI 1.1 utilities for Moja
rra
01:14:03,173 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC000001: Failed to start service jboss.deployment.unit."Fantasy.ear".WeldSt
artService: org.jboss.msc.service.StartException in service jboss.deployment.unit."Fantasy.ear".WeldStartService: Failed to start service
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_67]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_67]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_67]
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type TestBean with qualifiers @Default
  at injection point [BackedAnnotatedField] @Inject com.fantasy.web.Producer.bean
  at com.fantasy.web.Producer.bean(Producer.java:0)

    at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:372)
    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:293)
    at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:134)
    at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:167)
    at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:531)
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:68)
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:66)
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60)
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262) [rt.jar:1.7.0_67]
    ... 3 more

01:14:03,183 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014613: Operation ("deploy") failed - address: ([("depl
oyment" => "Fantasy.ear")]) - failure description: {"JBAS014671: Failed services" => {"jboss.deployment.unit.\"Fantasy.ear\".WeldStartService" => "org
.jboss.msc.service.StartException in service jboss.deployment.unit.\"Fantasy.ear\".WeldStartService: Failed to start service
    Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type TestBean with qualifiers @Default
  at injection point [BackedAnnotatedField] @Inject com.fantasy.web.Producer.bean
  at com.fantasy.web.Producer.bean(Producer.java:0)
"}}
01:14:03,253 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 28) JBAS018559: Deployed "Fantasy.ear" (runtime-name : "Fantasy.ear")
01:14:03,257 INFO  [org.jboss.as.controller] (Controller Boot Thread) JBAS014774: Service status report
JBAS014777:   Services which failed to start:      service jboss.deployment.unit."Fantasy.ear".WeldStartService: org.jboss.msc.service.StartException 
in service jboss.deployment.unit."Fantasy.ear".WeldStartService: Failed to start service

01:14:03,355 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management
01:14:03,356 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990
01:14:03,356 ERROR [org.jboss.as] (Controller Boot Thread) JBAS015875: WildFly 8.2.0.Final "Tweek" started (with errors) in 7986ms - Started 385 of 47
3 services (22 services failed or missing dependencies, 108 services are lazy, passive or on-demand)
01:14:03,500 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 51) JBAS011410: Stopping Persistence Unit (phase 2 of 2) Service 'Fantasy.ear#JPAD
B'
01:14:03,501 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 51) HHH000227: Running hbm2ddl schema export
01:14:03,544 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 51) HHH000230: Schema export complete
01:14:03,546 INFO  [org.jboss.weld.deployer] (MSC service thread 1-7) JBAS016009: Stopping weld service for deployment Fantasy.ear
01:14:03,580 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 51) JBAS011410: Stopping Persistence Unit (phase 1 of 2) Service 'Fantasy.ear#JPAD
B'
01:14:03,587 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015974: Stopped subdeployment (runtime-name: FantasyEjb.jar) in 99ms
01:14:03,587 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015974: Stopped subdeployment (runtime-name: FantasyWeb.war) in 99ms
01:14:03,589 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015877: Stopped deployment Fantasy.ear (runtime-name: Fantasy.ear) in
 101ms
01:14:03,699 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018558: Undeployed "Fantasy.ear" (runtime-name: "Fantasy.ear")
01:14:03,704 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report
JBAS014775:    New missing/unsatisfied dependencies:
      service jboss.deployment.subunit."Fantasy.ear"."FantasyEjb.jar".deploymentCompleteService (missing) dependents: [service jboss.deployment.unit."
Fantasy.ear".deploymentCompleteService] 
      service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."com.sun.faces.config.ConfigureListener".CREATE (missing) dependents: 
[service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."com.sun.faces.config.ConfigureListener".START] 
      service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."com.sun.faces.config.ConfigureListener".START (missing) dependents: [
service jboss.undertow.deployment.default-server.default-host./FantasyWeb.UndertowDeploymentInfoService, service jboss.undertow.deployment.default-ser
ver.default-host./FantasyWeb, service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".deploymentCompleteService] 
      service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."com.sun.faces.config.ConfigureListener".WeldInstantiator (missing) de
pendents: [service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."com.sun.faces.config.ConfigureListener".START] 
      service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."javax.faces.webapp.FacesServlet".CREATE (missing) dependents: [servic
e jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."javax.faces.webapp.FacesServlet".START] 
      service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."javax.faces.webapp.FacesServlet".START (missing) dependents: [service
 jboss.undertow.deployment.default-server.default-host./FantasyWeb.UndertowDeploymentInfoService, service jboss.undertow.deployment.default-server.def
ault-host./FantasyWeb, service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".deploymentCompleteService] 
      service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."javax.faces.webapp.FacesServlet".WeldInstantiator (missing) dependent
s: [service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."javax.faces.webapp.FacesServlet".START] 
      service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."javax.faces.webapp.FacetTag".CREATE (missing) dependents: [service jb
oss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."javax.faces.webapp.FacetTag".START] 
      service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."javax.faces.webapp.FacetTag".START (missing) dependents: [service jbo
ss.undertow.deployment.default-server.default-host./FantasyWeb.UndertowDeploymentInfoService, service jboss.undertow.deployment.default-server.default
-host./FantasyWeb, service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".deploymentCompleteService] 
      service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."javax.faces.webapp.FacetTag".WeldInstantiator (missing) dependents: [
service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."javax.faces.webapp.FacetTag".START] 
      service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV".CREATE (missing) depe
ndents: [service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV".START] 
      service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV".START (missing) depen
dents: [service jboss.undertow.deployment.default-server.default-host./FantasyWeb.UndertowDeploymentInfoService, service jboss.undertow.deployment.def
ault-server.default-host./FantasyWeb, service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".deploymentCompleteService] 
      service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV".WeldInstantiator (mis
sing) dependents: [service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV".START] 
      service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."javax.servlet.jsp.jstl.tlv.ScriptFreeTLV".CREATE (missing) dependents
: [service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."javax.servlet.jsp.jstl.tlv.ScriptFreeTLV".START] 
      service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."javax.servlet.jsp.jstl.tlv.ScriptFreeTLV".START (missing) dependents:
 [service jboss.undertow.deployment.default-server.default-host./FantasyWeb.UndertowDeploymentInfoService, service jboss.undertow.deployment.default-s
erver.default-host./FantasyWeb, service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".deploymentCompleteService] 
      service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."javax.servlet.jsp.jstl.tlv.ScriptFreeTLV".WeldInstantiator (missing) 
dependents: [service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."javax.servlet.jsp.jstl.tlv.ScriptFreeTLV".START] 
      service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."org.jboss.weld.servlet.WeldInitialListener".CREATE (missing) dependen
ts: [service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."org.jboss.weld.servlet.WeldInitialListener".START] 
      service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."org.jboss.weld.servlet.WeldInitialListener".START (missing) dependent
s: [service jboss.undertow.deployment.default-server.default-host./FantasyWeb.UndertowDeploymentInfoService, service jboss.undertow.deployment.default
-server.default-host./FantasyWeb, service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".deploymentCompleteService] 
      service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."org.jboss.weld.servlet.WeldInitialListener".WeldInstantiator (missing
) dependents: [service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."org.jboss.weld.servlet.WeldInitialListener".START] 
      service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."org.jboss.weld.servlet.WeldTerminalListener".CREATE (missing) depende
nts: [service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."org.jboss.weld.servlet.WeldTerminalListener".START] 
      service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."org.jboss.weld.servlet.WeldTerminalListener".START (missing) dependen
ts: [service jboss.undertow.deployment.default-server.default-host./FantasyWeb.UndertowDeploymentInfoService, service jboss.undertow.deployment.defaul
t-server.default-host./FantasyWeb, service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".deploymentCompleteService] 
      service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."org.jboss.weld.servlet.WeldTerminalListener".WeldInstantiator (missin
g) dependents: [service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."org.jboss.weld.servlet.WeldTerminalListener".START] 
      service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".deploymentCompleteService (missing) dependents: [service jboss.deployment.unit."
Fantasy.ear".deploymentCompleteService] 
      service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".ee.ComponentRegistry (missing) dependents: [service jboss.undertow.deployment.de
fault-server.default-host./FantasyWeb.UndertowDeploymentInfoService] 
      service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".jndiDependencyService (missing) dependents: [service jboss.deployment.subunit."F
antasy.ear"."FantasyWeb.war".component."javax.faces.webapp.FacesServlet".START, service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".compon
ent."javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV".START, service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."org.jboss.weld.
servlet.WeldInitialListener".START, service jboss.deployment.subunit."Fantasy.ear"."FantasyWeb.war".component."org.jboss.weld.servlet.WeldTerminalList
ener".START, JBAS014799: ... and 4 more ] 
      service jboss.deployment.unit."Fantasy.ear".WeldBootstrapService (missing) dependents: [service jboss.deployment.unit."Fantasy.ear".CdiValidator
FactoryService] 
      service jboss.deployment.unit."Fantasy.ear".WeldStartService (missing) dependents: [service jboss.deployment.unit."Fantasy.ear".CdiValidatorFact
oryService] 
      service jboss.persistenceunit."Fantasy.ear#JPADB" (missing) dependents: [service jboss.deployment.unit."Fantasy.ear".deploymentCompleteService] 
      service jboss.undertow.deployment.default-server.default-host./FantasyWeb (missing) dependents: [service jboss.deployment.subunit."Fantasy.ear".
"FantasyWeb.war".deploymentCompleteService] 
      service jboss.undertow.deployment.default-server.default-host./FantasyWeb.UndertowDeploymentInfoService (missing) dependents: [service jboss.und
ertow.deployment.default-server.default-host./FantasyWeb] 
JBAS014777:   Services which failed to start:      service jboss.deployment.unit."Fantasy.ear".WeldStartService

01:14:08,291 INFO  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 2) JBAS015003: Found Fantasy.ear in deployment directory. To 
trigger deployment create a file called Fantasy.ear.dodeploy

【问题讨论】:

  • 在我看来这更像是 Spring 配置的问题,所以我建议添加 Spring 和 Spring-annotation 标签。
  • @hagrawal 这不是春季项目。这是一个 Java EE 项目。
  • 如果你用@EJB而不是@Inject注入会发生什么?第二个建议:尝试将beans.xml 也添加到您的 EJB jar 中。
  • 您使用的是什么版本的 JBossAS/WildFly?
  • @RobbyCornelissen with EJB 语句没有显示任何错误。可能会与上下文一起使用。但我必须使用 Inject 因为这是我老师的命令。将 beans.xml 文件添加到 EJB 项目,但仍然有同样的错误。

标签: jakarta-ee jpa jboss cdi


【解决方案1】:

在 Java EE 6(在 JBoss AS 7.2 上)中,我通常通过在资源类中为 EJB 创建生产者来解决这个问题,如下所示:

public class Resources {
        @Produces
        @EJB
        private TestBean testBean;
}

这将允许您进一步@Inject 他们。不过,Java EE 7 中可能有更优雅的解决方案。

【讨论】:

    【解决方案2】:

    我将您的代码复制并粘贴到一个多模块项目中并构建它(使用 Maven)。

    部署到 WildFly 8.2.0.Final 后,我得到:

    22:38:17,236 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015876: Starting deployment of "FantasyEar.ear" (runtime-name: "FantasyEar.ear")
    22:38:17,291 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-10) JBAS015973: Starting subdeployment (runtime-name: "FantasyEjb.jar")
    22:38:17,291 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015973: Starting subdeployment (runtime-name: "FantasyWeb.war")
    22:38:17,328 INFO  [org.jboss.as.jpa] (MSC service thread 1-14) JBAS011401: Read persistence.xml for JPADB
    22:38:17,400 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 50) JBAS011409: Starting Persistence Unit (phase 1 of 2) Service 'FantasyEar.ear#JPADB'
    22:38:17,407 INFO  [org.hibernate.jpa.internal.util.LogHelper] (ServerService Thread Pool -- 50) HHH000204: Processing PersistenceUnitInfo [
        name: JPADB
        ...]
    22:38:17,450 INFO  [org.hibernate.Version] (ServerService Thread Pool -- 50) HHH000412: Hibernate Core {4.3.7.Final}
    22:38:17,451 INFO  [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 50) HHH000206: hibernate.properties not found
    22:38:17,452 INFO  [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 50) HHH000021: Bytecode provider name : javassist
    22:38:17,496 INFO  [org.jboss.weld.deployer] (MSC service thread 1-3) JBAS016002: Processing weld deployment FantasyEar.ear
    22:38:17,537 INFO  [org.hibernate.validator.internal.util.Version] (MSC service thread 1-3) HV000001: Hibernate Validator 5.1.3.Final
    22:38:17,616 INFO  [org.jboss.weld.deployer] (MSC service thread 1-4) JBAS016002: Processing weld deployment FantasyWeb.war
    22:38:17,617 INFO  [org.jboss.weld.deployer] (MSC service thread 1-15) JBAS016002: Processing weld deployment FantasyEjb.jar
    22:38:17,621 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-15) JNDI bindings for session bean named TestBean in deployment unit subdeployment "FantasyEjb.jar" of deployment "FantasyEar.ear" are as follows:
    
        java:global/FantasyEar/FantasyEjb/TestBean!com.fantasy.beans.TestBean
        java:app/FantasyEjb/TestBean!com.fantasy.beans.TestBean
        java:module/TestBean!com.fantasy.beans.TestBean
        java:global/FantasyEar/FantasyEjb/TestBean
        java:app/FantasyEjb/TestBean
        java:module/TestBean
    
    22:38:17,668 INFO  [org.jboss.weld.deployer] (MSC service thread 1-8) JBAS016005: Starting Services for CDI deployment: FantasyEar.ear
    22:38:17,690 INFO  [org.jboss.weld.Version] (MSC service thread 1-8) WELD-000900: 2.2.6 (Final)
    22:38:17,700 INFO  [org.jboss.weld.deployer] (MSC service thread 1-13) JBAS016008: Starting weld service for deployment FantasyEar.ear
    22:38:17,858 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 50) JBAS011409: Starting Persistence Unit (phase 2 of 2) Service 'FantasyEar.ear#JPADB'
    22:38:17,906 INFO  [org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 50) HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
    22:38:18,198 INFO  [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 50) HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
    22:38:18,203 WARN  [org.hibernate.dialect.H2Dialect] (ServerService Thread Pool -- 50) HHH000431: Unable to determine H2 database version, certain features may not work
    22:38:18,267 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (ServerService Thread Pool -- 50) HHH000397: Using ASTQueryTranslatorFactory
    22:38:18,466 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 50) HHH000227: Running hbm2ddl schema export
    22:38:18,471 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 50) HHH000389: Unsuccessful: drop sequence hibernate_sequence
    22:38:18,471 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 50) Sequence "HIBERNATE_SEQUENCE" not found; SQL statement:
    drop sequence hibernate_sequence [90036-173]
    22:38:18,472 INFO  [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 50) HHH000230: Schema export complete
    22:38:18,962 INFO  [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-7) Initializing Mojarra 2.2.8-jbossorg-1 20140822-1131 for context '/FantasyWeb'
    22:38:19,295 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-7) JBAS017534: Registered web context: /FantasyWeb
    22:38:19,335 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "FantasyEar.ear" (runtime-name : "FantasyEar.ear")
    

    我唯一遗漏的是 jboss-deployment-structure.xml 文件。此外,我确保每个部署描述符都是 Java EE 7 的最新版本。

    http://xmlns.jcp.org/xml/ns/javaee/application_7.xsd
    http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd
    http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd
    

    而且任何地方都没有 beans.xml!

    Fantasy.ear 文件的大小小于 9kb。如果你的比这大得多,那么你在某处有你不需要的罐子。日志消息Unable to obtain CDI 1.1 utilities for Mojarra 让我觉得您正在部署自己的 JSF 库。

    为了繁荣,可以在https://github.com/sfcoy/fantasy-demo找到工作源。

    【讨论】:

    • 所以也许我正在部署错误的库?问题是如何解决?
    • 删除所有包含 any javax.* 包中的类的 jar。重要的是要了解服务器将提供您需要的所有 API 和实现。您需要针对它们进行编译,但不要将它们包含在可部署的工件中。
    • @PrzemysławJasiński 我在 GitHub 上发布代码只是为了你 ;-)
    猜你喜欢
    • 1970-01-01
    • 2015-08-17
    • 1970-01-01
    • 1970-01-01
    • 2014-06-05
    • 1970-01-01
    • 2015-12-19
    • 1970-01-01
    • 2012-10-16
    相关资源
    最近更新 更多