I do have the same issue as explained here: JBoss7.1.3: @EJB works while @Inject fails Presumably that is even the same setup (Wildfly 8.0).
Despite having a Resource class with producer, I cannot inject a Logger instance. Neiter in the Controller, nor into the EJB. [Question 1] Correct me if I'm wrong, I should be able to inject them into @Model beans and into beans annotated with @Stateless (EJB), shouldn't I?
package com.doe.webapp.service.auxilliary.cdiproducer;
import javax.enterprise.context.Dependent;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.faces.context.FacesContext;
import org.apache.log4j.Logger;
@Dependent
public class Resources {
@Produces
public Logger produceLog(InjectionPoint injectionPoint) {
return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
}
@Produces
@RequestScoped
public FacesContext produceFacesContext() {
return FacesContext.getCurrentInstance();
}
}
Here is the start of my Controller:
package com.doe.webapp.controller.security;
import java.io.IOException;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.enterprise.inject.Model;
import javax.enterprise.inject.Produces;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedProperty;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.Pattern;
import org.slf4j.Logger;
import com.doe.webapp.model.usermgmt.User;
import com.doe.webapp.service.security.LoginService;
@Model
public class LoginController {
private static final String ADMIN = "admin";
@Inject
private Logger log;
@Inject
private FacesContext facesContext;
@Inject
private LoginService loginService;
[...]
Here is the EJB, which is also Injected in the @Model annotated class. Likewise the Logger. While the former works, the injection of the Logger throws the previously explained error.
package com.doe.webapp.service.security;
import java.util.logging.Logger;
import javax.ejb.Stateless;
import javax.enterprise.event.Event;
import javax.inject.Inject;
import com.doe.webapp.data.UserRepository;
import com.doe.webapp.model.usermgmt.User;
@Stateless
public class LoginService {
@Inject
private transient Logger log;
@Inject
private UserRepository repository;
@Inject
private Event<User> userEvent;
public User login(User user) {
log.info("login " + user.getUsername());
User rUser = repository.findByCredentials(user.getUsername(), user.getPassword());
return rUser;
}
}
Now, I get an error for the LoginController.java Controller.
WELD-001408: Unsatisfied dependencies for type Logger with qualifiers @Default
at injection point [BackedAnnotatedField] @Inject private com.doe.webapp.controller.security.LoginController.log
at com.doe.webapp.controller.security.LoginController.log(LoginController.java:0)
And another one for the LoginService.java Enterprise Bean.
WELD-001408: Unsatisfied dependencies for type Logger with qualifiers @Default
at injection point [BackedAnnotatedField] @Inject private transient com.doe.webapp.service.security.LoginService.log
at com.doe.webapp.service.security.LoginService.log(LoginService.java:0)
[Question 2]: What am I not understanding that this injection fails with the WELD-001408 error.