【问题标题】:error inject EJB in JSF project在 JSF 项目中注入 EJB 时出错
【发布时间】:2018-05-26 12:10:50
【问题描述】:

大家好,我是 java EE 的新手,我想用 EJB 和 JSF 开发一个应用程序,当我想在 web dynamique 项目中注入我的 JAR 时,我遇到了这个错误,我什么都不懂,请任何人都可以帮助我

17:54:06,324 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-8) MSC000001: Failed to start service jboss.deployment.unit."PGestion.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."PGestion.war".INSTALL: WFLYSRV0153: Failed to process phase INSTALL of deployment "PGestion.war"
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:172)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:2032)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1955)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEJB0406: No EJB found with interface of type 'com.bestofgeeks.gestion.dao.Implement.GestionDAOBean' for binding com.bestofgeeks.gestion.services.ImplService.ImplServiceProduct/product
    at org.jboss.as.ejb3.deployment.processors.EjbInjectionSource.getResourceValue(EjbInjectionSource.java:90)
    at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.addJndiBinding(ModuleJndiBindingProcessor.java:211)
    at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor$1.handle(ModuleJndiBindingProcessor.java:182)
    at org.jboss.as.ee.component.ClassDescriptionTraversal.run(ClassDescriptionTraversal.java:54)
    at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.processClassConfigurations(ModuleJndiBindingProcessor.java:186)
    at org.jboss.as.ee.component.deployers.ModuleJndiBindingProcessor.deploy(ModuleJndiBindingProcessor.java:143)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:165)
    ... 5 more

17:54:06,341 INFO  [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-2) ISPN000128: Infinispan version: Infinispan 'Chakra' 8.2.8.Final
17:54:06,696 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 62) WFLYCLINF0002: Started client-mappings cache from ejb container
17:54:06,777 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "PGestion.war")]) - failure description: {
    "WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"PGestion.war\".INSTALL" => "WFLYSRV0153: Failed to process phase INSTALL of deployment \"PGestion.war\"
    Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEJB0406: No EJB found with interface of type 'com.bestofgeeks.gestion.dao.Implement.GestionDAOBean' for binding com.bestofgeeks.gestion.services.ImplService.ImplServiceProduct/product"},
    "WFLYCTL0412: Required services that are not installed:" => ["jboss.deployment.unit.\"PGestion.war\".beanmanager"],
    "WFLYCTL0180: Services with missing/unavailable dependencies" => [
        "jboss.deployment.unit.\"PGestion.war\".weld.weldClassIntrospector is missing [jboss.deployment.unit.\"PGestion.war\".beanmanager]",
        "jboss.deployment.unit.\"PGestion.war\".batch.artifact.factory is missing [jboss.deployment.unit.\"PGestion.war\".beanmanager]"
    ]
}

这是DAO接口:

package com.bestofgeeks.gestion.dao; 

import java.util.List; 
import javax.ejb.Local; 
import com.bestofgeeks.gestion.entity.products; 

@Local 
public interface IGestion { 
  public void delete(products p); 
  public products persiste(products p); 
  public List<products> selectAll(); 
} 

接口 DAO

package com.bestofgeeks.gestion.dao;

import java.util.List;

import javax.ejb.Local;

import com.bestofgeeks.gestion.entity.products;

@Local
public interface IGestion   {

    public void delete(products p);
    public products persiste(products p);
    public List<products> selectAll();

}

实现 DAO

package com.bestofgeeks.gestion.dao.Implement;


import java.util.List;

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

import com.bestofgeeks.gestion.dao.IGestion;
import com.bestofgeeks.gestion.entity.products;
@Stateless
public class GestionDAOBean implements IGestion{
    @PersistenceContext(unitName = "Gestion_PU") 
    EntityManager entityManager;

    @Override
    public void delete(products p) {
        // TODO Auto-generated method stub
        entityManager.remove(p);

    }

    @Override
    public products persiste(products p){
        // TODO Auto-generated method stub
        entityManager.persist(p);
        return p;

        }

    @Override
    public List<products> selectAll() {
        // TODO Auto-generated method stub
         Query query = (Query) entityManager.createQuery("SELECT o from products o");
            return ((javax.persistence.Query) query).getResultList();
    }



}

这是我项目的打包服务 该服务具有接口 Iservice 和一个实现类名 ImplServiceProduct 的包 对于 Iservice,这是代码

    package com.bestofgeeks.gestion.services;

import java.util.List;

import javax.ejb.Local;

import com.bestofgeeks.gestion.entity.products;

@Local
public interface Iservices {
    public List<products> selectAll();
    public void delete(products p);
    public products persiste(products p);
}

实施服务

    package com.bestofgeeks.gestion.services.ImplService;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import com.bestofgeeks.gestion.dao.Implement.GestionDAOBean;
import com.bestofgeeks.gestion.entity.products;
import com.bestofgeeks.gestion.services.Iservices;

@Stateless
public class ImplServiceProduct implements Iservices{
    @EJB
    GestionDAOBean product;


    @Override
    public List<products> selectAll() {

        return product.selectAll();
    }

    @Override
    public void delete(products p) {
        // TODO Auto-generated method stub
        product.delete(p);

    }

    @Override
    public products persiste(products p) {
        // TODO Auto-generated method stub
        return product.persiste(p);
    }


}

对于实体

    package com.bestofgeeks.gestion.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table
public class products {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long id;
    @Column
    private String nameproduct;
    @Column
    private String reference;
    @Column
    private Date dateposte;
    public products(String nameproduct, String reference, Date dateposte) {
        super();
        this.nameproduct = nameproduct;
        this.reference = reference;
        this.dateposte = dateposte;
    }
    public products() {
        super();
        // TODO Auto-generated constructor stub
    }
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getNameproduct() {
        return nameproduct;
    }
    public void setNameproduct(String nameproduct) {
        this.nameproduct = nameproduct;
    }
    public String getRefence() {
        return reference;
    }
    public void setRefences(String reference) {
        this.reference = reference;
    }
    public Date getDateposte() {
        return dateposte;
    }
    public void setDateposte(Date dateposte) {
        this.dateposte = dateposte;
    }


}

对于我的 jsf 项目 我创建一个控制器 这是代码

    package com.bestofgeeks.gestion.controllers;

import javax.annotation.ManagedBean;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;


import com.bestofgeeks.gestion.services.Iservices;

@RequestScoped @ManagedBean
public class myProduct {
@EJB
    public String name = "noredine";

    Iservices service;







}

【问题讨论】:

  • 你能贴一些代码吗?
  • 请添加更多,这不足以帮助您。并将其添加到不在评论中的问题中。
  • 请按下方的编辑“按钮”来编辑您的问题,而不是在评论中添加。而且这里没有JSF相关的代码,也没有jpa和java-ee太宽泛。尝试创建一个minimal reproducible example
  • 读取错误:(强调我的)“找不到类型为 'com.bestofgeeks.gestion.dao.Implement.GestionDAOBean 的 接口 的 EJB” 它引用的是一个实现,而不是一个接口!

标签: eclipse jsf jpa jakarta-ee ejb


【解决方案1】:

您必须注入本地接口而不是 bean:

@EJB
IGestion product;

正如@kukeltje 在评论中所说:

阅读错误:(强调我的)“没有找到类型为接口的 EJB 'com.bestofgeeks.gestion.dao.Implement.GestionDAOBean" 和它是什么 references 是一个 impl,而不是

一个界面!

【讨论】:

  • 正如错误中明确指出的(正如我评论的那样)。也许将此添加到答案中,以便其他“学习”阅读错误,因为它们大多非常明确
猜你喜欢
  • 1970-01-01
  • 2014-03-19
  • 2012-08-01
  • 2012-01-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-28
  • 2013-08-03
相关资源
最近更新 更多