5

두 개의 인터페이스 (원격 및 로컬)를 구현하는 @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의 요청에 : 편집

  1. 을 WeatherDataBean가 있습니다이있다

    import javax.ejb.LocalBean; 
    import javax.ejb.Stateless; 
    import javax.inject.Inject; 
    
  2. 자원을 :

    import javax.enterprise.inject.Produces; 
    import javax.faces.context.FacesContext; 
    import javax.inject.Singleton; 
    import javax.persistence.EntityManager; 
    import javax.persistence.PersistenceContext; 
    
+0

모든 것이 올바르게 보입니다. 올바른 주석 (패키지 확인)을 가지고 있습니까? 또한 물건 포장 방법에 따라 다를 수 있습니다. – LightGuard

+0

내 대답을 확인하십시오.이 주석에 어떤 패키지를 사용했는지 추가했습니다. 나는 EJB 프로젝트, EJBClient 프로젝트, JPA 프로젝트 및 JSF 프로젝트를 패키징하기 위해 EAR 프로젝트를 사용하고있다. –

+0

아, 네가 EAR을 사용한다면 조금 바뀌어. 주입을하고있는 곳, 클래스가있는 라이브러리, beans.xml 파일의 위치를 ​​지정해야합니다. – LightGuard

답변

5

난 그냥 내 프로젝트

import java.util.logging.Logger; 

import javax.enterprise.context.RequestScoped; 
import javax.enterprise.inject.Produces; 
import javax.enterprise.inject.spi.InjectionPoint; 
import javax.faces.context.FacesContext; 
import javax.persistence.EntityManager; 
import javax.persistence.PersistenceContext; 

/** 
* This class uses CDI to alias Java EE resources, such as the persistence context, to CDI beans 
* 
* <p> 
* Example injection on a managed bean field: 
* </p> 
* 
* <pre> 
* &#064;Inject 
* private EntityManager em; 
* </pre> 
*/ 
public class Resources { 
    // use @SuppressWarnings to tell IDE to ignore warnings about field not being referenced directly 
    @SuppressWarnings("unused") 
    @Produces 
    @PersistenceContext 
    private EntityManager em; 

    // @Produces 
    // public Logger produceLog(InjectionPoint injectionPoint) { 
    // return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName()); 
    // } 

    @Produces 
    @RequestScoped 
    public FacesContext produceFacesContext() { 
     return FacesContext.getCurrentInstance(); 
    } 

} 
6

나는 유사한 오류로 실행하려면이 클래스를 추가하여이 고정, 같은 문제가 있었다, 나는 콩을 넣어하지 않았다 밝혀졌다. xml 파일을 WEB-INF 폴더에 저장하십시오. beans.xml 파일은 WEB-INF 폴더에있는 빈 파일 일 수 있습니다. JBossAS는 해당 파일을 검사하여 CDI 서비스를 시작합니다.