无法为ejb转换ejbRef

Luc*_*uke 4 java java-ee cdi

QuestionCommonBusiness

public interface QuestionCommonBusiness {

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

    List<Question> all();
}
Run Code Online (Sandbox Code Playgroud)

QuestionLocalBusiness

public interface QuestionLocalBusiness extends QuestionCommonBusiness {

}
Run Code Online (Sandbox Code Playgroud)

QuestionManagerEJB

@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();
    }
}
Run Code Online (Sandbox Code Playgroud)

QuestionController(JSF bean)...我不知道我是否正确使用它

 @Named
    @RequestScoped
    public class QuestionController {

    @Inject
    private QuestionLocalBusiness questionManager;

    private List<Question> questions;

    @PostConstruct
    public void initialize() {
        questions = questionManager.all();
    }

    public List<Question> getQuestions() {
        return questions;
    }

}
Run Code Online (Sandbox Code Playgroud)

错误

HTTP Status 500 -

type Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: WELD-000049 Unable to invoke [method] @PostConstruct public
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

Com.myapp.interfaces.QuestionController.initialize()com.myapp.interfaces.QuestionController@29421836

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
Run Code Online (Sandbox Code Playgroud)

com.myapp.application.QuestionCommonBusiness

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.
Run Code Online (Sandbox Code Playgroud)

Bal*_*usC 5

此问题与Glassfish焊接问题16186有关.选择了错误的接口@Local,即最外层的接口.

你有两个选择:

  1. 只需使用@EJB.
  2. 摆脱QuestionCommonBusiness超级接口.

不用说选项1是首选.