Hey all,
I'm just starting out with spring data and I'm trying to add a custom method to my repositories which requires another bean (which is preferably only created once (i.e. singleton))
The bean is declared in the root-context.xml like so
Which I then try to inject using @Autowired
However when running the code I get a NullPointerException. If I do the wiring in a @Controller and then passing the reference to the repository it works, but I don't want to DI to happen in the controller.
Full code is available on GitHub https://github.com/joelkuiper/trialv...tQueryTemplate
Thanks in advance!
I'm just starting out with spring data and I'm trying to add a custom method to my repositories which requires another bean (which is preferably only created once (i.e. singleton))
The bean is declared in the root-context.xml like so
Code:
<bean class="org.drugis.trialverse.CachedQueryTemplateFactory" />
Code:
@Getter
@Setter
@Component
public class StudyRepositoryImpl implements StudyRepositoryCustom {
@PersistenceContext private EntityManager d_em;
@Autowired private QueryTemplateFactory queryTemplateFactory;
@Override
@SuppressWarnings("unchecked")
public List<Study> findStudies(
UUID indication,
List<UUID> variables,
List<UUID> treatments) {
QueryTemplate template = this.queryTemplateFactory.buildQueryTemplate("/studiesQuery.template.sql");
...
}
}
Full code is available on GitHub https://github.com/joelkuiper/trialv...tQueryTemplate
Thanks in advance!