Announcement Announcement Module
No announcement yet.
Autowired beans are null in CustomRepositoryImpl Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Autowired beans are null in CustomRepositoryImpl

    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

    <bean class="org.drugis.trialverse.CachedQueryTemplateFactory" />
    Which I then try to inject using @Autowired

    public class StudyRepositoryImpl implements StudyRepositoryCustom {
    	@PersistenceContext private EntityManager d_em;
    	@Autowired private QueryTemplateFactory queryTemplateFactory;
    	public List<Study> findStudies(
    			UUID indication,
    			List<UUID> variables,
    			List<UUID> treatments) {
    		QueryTemplate template = this.queryTemplateFactory.buildQueryTemplate("/studiesQuery.template.sql");
    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

    Thanks in advance!
    Last edited by casualconnect; Apr 22nd, 2013, 07:11 AM.