错误在JSF项目中注入EJB

时间:2017-12-12 18:01:44

标签: eclipse jsf jpa java-ee ejb

大家好我是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;







}

1 个答案:

答案 0 :(得分:2)

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

@EJB
IGestion product;
  

正如@kukeltje在评论中所说:

     

阅读错误:(强调我的)&#34;找不到带有类型接口的EJB   &#39; com.bestofgeeks.gestion.dao.Implement.GestionDAOBean&#34;什么呢   引用是一个impl,而不是

界面!