【问题标题】:refer to several JavaBeans Enterprise参考几个JavaBeans Enterprise
【发布时间】:2018-01-22 18:11:41
【问题描述】:

我在编写 EJB 应用程序时遇到问题。我搜索了一个解决方案,但 glassfish 仍然存在同样的问题:

cannot Deploy EducationPortal
deploy is failing=Error occurred during deployment: Exception while deploying the app [EducationPortal] : 
Warning : Unable to determine local  business vs. remote business designation for  EJB 3.0 ref Local ejb-ref     
name=com.portal.education.servlet.ModuleController/moduleServiceLocal,Local 3.x
interface =com.portal.education.service.Module.ModuleServiceLocal,ejb-
link=ModuleServiceImpl,lookup=,mappedName=,jndi-name=,refType=Session. 
Please see server.log for more details.

为了使用某些方法,我必须在同一个 servlet 中引用多个 EJB 我应该怎么做才能得到正确的结果

@EJB (beanName = "ModuleServiceImpl") 

private ModuleServiceLocal moduleServiceLocal;
@EJB(beanName = "TeacherServiceImpl") 
private TeacherServiceLocal teacherServiceLocal;
@EJB(beanName = "LevelServiceImpl") 
private LevelServiceLocal levelServiceLocal;
@EJB(beanName = "SubjectServiceImpl") 
private SubjectServiceLocal subjectServiceLocal;

接口 ModuleServiceLocal

import java.util.List;

import javax.ejb.Local;

import com.issatso.portal.education.domain.*;
import com.issatso.portal.education.domain.Module.Id;

@Local
 public interface ModuleServiceLocal {



    Module find(Id idModule);
    List<Module> findAll();

    void delete(Id idModule);

    Module save(Module object);

}

类 ModuleServiceImpl

import java.util.List;

import javax.ejb.Singleton;
import javax.inject.Inject;

import com.issatso.portal.education.dao.module.ModuleDao;
import com.issatso.portal.education.domain.Module.Id;
import com.issatso.portal.education.domain.Module;

@Singleton
  public class ModuleServiceImpl   implements ModuleServiceLocal  {


    @Inject
    private ModuleDao dao;

    public Module find(Id idModule) {
        return (Module) this.dao.find(idModule);
    }

    public List<Module> findAll() {
        return this.dao.findAll();
    }

    public void delete(Id idModule) {
        this.dao.delete(idModule);

    }

    public Module save(Module object) {
        String action = (object.getIdModule()!= null) ? "UPDATED" : "CREATED";
        Module Module = (com.issatso.portal.education.domain.Module) this.dao.save(object);
        return Module;
    }


    }

【问题讨论】:

标签: jakarta-ee glassfish ejb


【解决方案1】:

您可以在 servlet 中使用 @Inject 来注入 bean。而且您不需要定义beanName。就这样吧:

@Inject
private ModuleServiceLocal moduleServiceLocal;
@Inject
private TeacherServiceLocal teacherServiceLocal;
[...]

您正在 bean ModuleServiceImpl 中实现接口 ModuleServiceLocal,因此 CDI 能够通过它找到类。

【讨论】:

    猜你喜欢
    • 2015-07-16
    • 2015-11-06
    • 2017-02-05
    • 2017-10-24
    • 2010-10-01
    • 1970-01-01
    • 2012-04-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多