我想注入默认的 Java 记录器。然而,Eclipse 强调它并声明“没有 bean 有资格注入到注入点 [JSR-299 §5.2.1]”
如果我仍然部署,则会引发以下异常。为什么注入Java Logger失败?EntityManager 相同,但我自己的 UserRepository Bean 则不然。
org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [Logger] with qualifiers [@Default] at injection point [[field]
代码:
import java.util.logging.Logger;
import javax.ejb.Stateless;
import javax.enterprise.event.Event;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import com.terry.webapp.data.UserRepository;
import com.terry.webapp.model.usermgmt.User;
// The @Stateless annotation eliminates the need for manual transaction demarcation
@Stateless
public class LoginService {
@Inject
private Logger log;
@Inject
private EntityManager em;
@Inject
private UserRepository repository;
public User login(User user) {
log.info("login " + user.getUsername());
User rUser = repository.findByCredentials(user.getUsername(), user.getPassword());
return rUser;
}
}