Hi guys,
I am trying to inject DomainWrapperFactory
(to then retrieve a VisitDomainWrapper
).
When I try to get it using annotations, domainWrapperFactory
is null
:
@Qualifier("domainWrapperFactory")
@Autowired
protected DomainWrapperFactory domainWrapperFactory;
Though using the Context
to get the component works just fine:
domainWrapperFactory = Context.getRegisteredComponent("domainWrapperFactory", DomainWrapperFactory.class);
(Q) What should I add to make annotation based injection work in my class?
See the complete class:
public class BeforeEndVisitAdvice implements MethodBeforeAdvice{
protected static final Log log = LogFactory.getLog(BeforeEndVisitAdvice.class);
protected DomainWrapperFactory domainWrapperFactory;
@Override
public void before(Method method, Object[] args, Object target) throws Throwable {
if (method.getName().equals("endVisit") && (target instanceof VisitService)) {
// Using the Context to retrieve a component instead of @Autowired
domainWrapperFactory = Context.getRegisteredComponent("domainWrapperFactory", DomainWrapperFactory.class);
Visit visit = (Visit) args[0];
VisitDomainWrapper visitDomainWrapper = domainWrapperFactory.newVisitDomainWrapper(visit);
visitDomainWrapper.setVisit(visit);
List<Diagnosis> diags = visitDomainWrapper.getUniqueDiagnoses(true, false);
if (diags.isEmpty()) {
log.error("Unable to save the visit. Visit (" + visit.getId() + ") must have at lease one primary diagnosis.");
throw new APIException();
}
}
return;
}
}