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

后端 未结 3 835
故里飘歌
故里飘歌 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:48

    One of the possible reasons you might not be willing to use the interface to inject the EJB could be that you might have many EJBs implementing this interface and your EJB container might be complaining that it's not able to resolve the ambiguity of which particular EJB has to be injected in a given context. If this is the case, you can easily specify the name of the concrete EJB class implementing the common interface using javax.inject.Named annotation as shown below:

    @SessionScoped
    class Scoped {
       @Named("Bean")
       IBean iBean;
    }
    

提交回复
热议问题