I have written a very simple application, but CDI does not work as expected:
the definition
@EJB private CustomerProviderSessionBeanLocal customerProvider;
does not lead to an instance of the bean.
Definition of my stateless session bean
@Local
public interface CustomerProviderSessionBeanLocal { ... }
@Stateless
@EJB(name="ejb/CustomerProvider", beanInterface = CustomerProviderSessionBeanLocal.class, beanName = "CustomerProviderSessionBean")
public class CustomerProviderSessionBean implements
CustomerProviderSessionBeanLocal ...
Controller Bean (for JSF):
@SessionScoped @ManagedBean
public class BackingBean {
@EJB private CustomerProviderSessionBeanLocal customerProvider;
JBoss yields:
java:global/2017_JEE_App_1_war_exploded/CustomerProviderSessionBean!beans.CustomerProviderSessionBeanLocal
java:app/2017_JEE_App_1_war_exploded/CustomerProviderSessionBean!beans.CustomerProviderSessionBeanLocal
java:module/CustomerProviderSessionBean!beans.CustomerProviderSessionBeanLocal
java:global/2017_JEE_App_1_war_exploded/CustomerProviderSessionBean
java:app/2017_JEE_App_1_war_exploded/CustomerProviderSessionBean
java:module/CustomerProviderSessionBean
Still, the attribute customerProvider is not initialized. The constructor has been called (can be seen in the log-file). I have tried several variants (with/without names, local interface, etc.). Using JNDI-Lookup does work:
initialContext = new InitialContext();
Object o = initialContext.lookup("java:app/2017_JEE_App_1_war_exploded/CustomerProviderSessionBean");
Using the same JNDI-Name in the @EJB-annotation does not work
I haven't changed the wildfly configuration!
Can anyone help?
It looks like your JSF controller is using the JSF managed bean feature instead of CDI. In this case
@EJB
won't work correctly. You should declare your class like this: