CDI 및 클래스 상속에 어려움을 겪고 있습니다. 나는 JAX-RS 컨트롤러로 선언 한 로 :이 컨트롤러는 기본 컨트롤러를 확장jax-rs 컨트롤러의 기본 클래스에서 CDI 주입이 수행되지 않았습니다.
@Path("/share")
public class ControllerShare extends BaseController {
@Inject
private ServiceShare serviceShare;
@PostConstruct
private void verifInit() throws ExceptionTechnique {
log.warn("Checking CDI injection");
if (serviceShare == null) {
log.error("serviceAccount not initialized. Check your EJB configuration");
throw new ExceptionTechnique("serviceShare not initialized. Check your EJB configuration.");
}
}
...
}
선언 :
public abstract class BaseController {
private Logger log = LoggerFactory.getLogger(ControllerShare.class);
@Context protected HttpServletRequest request;
@Inject private ControlerSession ctrlSession;
public BaseController() {}
@PostConstruct
private void verifInit() throws ExceptionTechnique {
log.warn("Checking CDI injection");
if (ctrlSession == null) {
log.error("controllerSession not initialized. Check your CDI configuration");
throw new ExceptionTechnique("serviceAccount not initialized. Check your CDI configuration.");
}
}
...
}
문제는 분사가 제대로 ControllerShare에서 수행된다는 점이다 (I 제대로 "을 참조하십시오 Checking CDI injection "), BaseController 클래스에서는 수행되지 않습니다 (ctrlSession이 null 임). @Named 및 기타 조합을 성공없이 시도합니다. 주입은 ControllerShare에서 수행되며 BaseController에서는 수행되지 않습니다.
편집 : 한 가지 더 : 호기심 @Context 잘 노력하고 있습니다. 내 요청이 설정되어 있고 값이 정확합니다.
감사합니다. 설명 및 솔루션을 제공해 주셔서 감사합니다.
매우 혼란 스럽지만 두 가지 객체가있는 것처럼 말하면서 두 가지 @PostContruct 메서드가 표시되는지 여부를 알 수 없습니다. AIUI 여기서 질문 할 수있는 유일한 질문은 다음과 같습니다. 인스턴스의 ctrlSession 필드가 null 또는 null이 아닌가요? – covener