Java 无法为ejb转换ejbRef

Java 无法为ejb转换ejbRef,java,jakarta-ee,cdi,Java,Jakarta Ee,Cdi,问题公共业务 public interface QuestionCommonBusiness { void create(Question question); void update (Question question); void delete(Question question); Question read(Integer id); List<Question> all(); } public interface Questio

问题公共业务

public interface QuestionCommonBusiness {

    void create(Question question);
    void update (Question question);
    void delete(Question question);
    Question read(Integer id);

    List<Question> all();
}
public interface QuestionLocalBusiness extends QuestionCommonBusiness {

}
问题管理器jb

@Stateless
@Local(QuestionLocalBusiness.class)
public class QuestionManagerEJB implements QuestionLocalBusiness {

    @PersistenceContext(unitName = "MyPU")
    private EntityManager entityManager;

    @Override
    public void create(Question question) {
        entityManager.persist(question);
    }

    @Override
    public void update(Question question) {
        entityManager.merge(question);
    }

    @Override
    public void delete(Question question) {
        entityManager.remove(question);
    }

    @Override
    public Question read(Integer id) {
        return entityManager.find(Question.class, id);
    }

    @Override
    public List<Question> all() {

        TypedQuery<Question> query = entityManager.createNamedQuery(
                "allQuestions", Question.class);
        return query.getResultList();
    }
}
上的com.myapp.interfaces.QuestionController.initialize() com.myapp.interfaces。QuestionController@29421836

root cause

org.jboss.weld.exceptions.WeldException: WELD-000049 Unable to invoke [method] @PostConstruct public
root cause

java.lang.reflect.InvocationTargetException

root cause

java.lang.IllegalStateException: Unable to convert ejbRef for ejb QuestionManagerEJB to a business object of type interface
上的com.myapp.interfaces.QuestionController.initialize() com.myapp.interfaces。QuestionController@29421836

root cause

org.jboss.weld.exceptions.WeldException: WELD-000049 Unable to invoke [method] @PostConstruct public
root cause

java.lang.reflect.InvocationTargetException

root cause

java.lang.IllegalStateException: Unable to convert ejbRef for ejb QuestionManagerEJB to a business object of type interface
com.myapp.application.commonbusiness

note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.1.1 logs.
这个问题涉及到。为
@Local
选择了错误的接口,即超快接口

您有两种选择:

  • 只需使用
    @EJB
  • 摆脱
    问题CommonBusiness
    超级界面

  • 不用说,首选选项1。

    或者您可以在@Local注释中包含QuestionCommonBusiness.class:

       @Stateless
       @Local({QuestionLocalBusiness.class, QuestionCommonBusiness.class)
       public class QuestionManagerEJB implements QuestionLocalBusiness {
          ...
    

    如果您使用
    @EJB
    而不是
    @Inject
    ,它能工作吗?如果你把
    @Local
    放在接口上而不是具体的实现上会怎么样?当我在JSFbean中将(@)注入(@)EJB时,它就会工作。我将beans.xml放在WEB-INF文件夹中,其余项目(EJB项目、JPA项目……使用Eclipse向导制作)的META-INF中。好吧,这将是另一个焊接缺陷。在您的情况下,为
    @Local
    选择了错误的接口。似乎与此相关: