2
기본 Java 로거를 주입하고 싶습니다. 그러나 이클립스는 그것을 강조하고 "콩은 주입 지점 [[JSR-299 §5.2.1]에 주입 할 수 없습니다."주입 지점에 주입 할 수있는 콩이 없습니다 [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;
}
}
수있다, 당신의
persistence.xml
에@PersistenceContext(unitName="pscontext")
를 사용하여 주입합니다 : @가 PersistenceContex (unitName = "pscontext @ 생산 ") EntityManager em; @ Inject the EntityManager를 원할 경우. –자신 만의 제작자를 만들어야 할 때와 간단한 사용자 @ 인젝터에 적용 할 수있는 경우를 이해하지 못합니다. 이것에 대한 전제 조건은 무엇입니까? – feder
이 게시물을 확인하면 제작자 방법에 대해 더 자세히 알 수 있습니다. http://stackoverflow.com/questions/16534728/please-explain-the-produces-annotation-in-cdi. Like @ AVolpe..mentioned 다른 클래스에서'producer 메소드'와'Inject'를 생성하기 위해'producer method '를 사용하면 이름을 변경할 때'@ PersistenceContext'의 이름을 바꾸기 위해 모든 장소를 찾을 필요가 없습니다 'persistence.xml' – SRy