두 개의 인터페이스 (원격 및 로컬)를 구현하는 @Stateless
bean이 있습니다. 또한 no-interface view를 사용하여 bean에 접근하기위한 @LocalBean
anotation을 추가했다. EJB에서WELD-001408 EntityManager를 주입 할 때 불완전한 의존성
@PersistenceContext(unitName="WeatherStationJPA")
private EntityManager entityManager;
과는 아무 문제없이 작동합니다 이제 이전에 내가 사용한
We use the "resource producer" pattern, from CDI, to "alias" the old fashioned @PersistenceContext injection of the entity manager to a CDI style injection. This allows us to use a consistent injection style (@Inject) throughout the application.
을 :
@Stateless
@LocalBean
public class WeatherDataBean implements WeatherDataBeanRemote, WeatherDataBeanLocal {
@Inject
private EntityManager entityManager;
public WeatherDataBean() {
}
// ....attributes, getter & setter methods ....
}
나는 from this example of JBoss AS7 quickstart을 찍은 이유 @Inject
를 사용합니다.
WELD-001408 Unsatisfied dependencies for type [EntityManager] with qualifiers [@Default] at injection point [[field] @Inject private ejb.WeatherDataBean.entityManager]
가 어떻게이 클래스의 자원이 정의되어있다 : 그러나 @Inject
주석이 오류를 얻을
public class Resources {
@SuppressWarnings("unused")
@PersistenceContext(unitName="WeatherStationJPA")
@Produces
private EntityManager entityManager;
@Produces
FacesContext getFacesContext() {
return FacesContext.getCurrentInstance();
}
}
이유는 엔티티 관리자를 삽입하려고하면 나는이 오류를 얻을 수 있습니까? 내가 주석을 참조하기 위해 사용하고 패키지를 추가하고 @LightGuard의 요청에 : 편집
이을 WeatherDataBean가 있습니다이있다
import javax.ejb.LocalBean; import javax.ejb.Stateless; import javax.inject.Inject;
자원을 :
import javax.enterprise.inject.Produces; import javax.faces.context.FacesContext; import javax.inject.Singleton; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext;
모든 것이 올바르게 보입니다. 올바른 주석 (패키지 확인)을 가지고 있습니까? 또한 물건 포장 방법에 따라 다를 수 있습니다. – LightGuard
내 대답을 확인하십시오.이 주석에 어떤 패키지를 사용했는지 추가했습니다. 나는 EJB 프로젝트, EJBClient 프로젝트, JPA 프로젝트 및 JSF 프로젝트를 패키징하기 위해 EAR 프로젝트를 사용하고있다. –
아, 네가 EAR을 사용한다면 조금 바뀌어. 주입을하고있는 곳, 클래스가있는 라이브러리, beans.xml 파일의 위치를 지정해야합니다. – LightGuard