Is it possible to inject EJB implementation and not its interface using CDI?

后端 未结 3 870
故里飘歌
故里飘歌 2021-02-01 09:37

My configuration is: Wildfly 8.2.0, Weld

Is it possible to inject in bean and not in its interface in CDI ?

@Stateless
class Bean implements IBean {
...
         


        
3条回答
  •  被撕碎了的回忆
    2021-02-01 09:54

    It looks like you got an unclear answer in your prior question, and really all this question is is a follow up to that one.

    Generally speaking, CDI allows you to inject both interface and impl for CDI managed beans. This is not the case for EJBs. When an EJB implements an interface, that becomes its business interface. Only the methods declared there are valid. Effectively, your Bean class defines only how those methods work, and does not actually exist as a bean in your runtime.

    So no, when using EJBs, you cannot inject the implementation, only the interface. If you really want to do this, I would move away from EJBs.

提交回复
热议问题