Announcement Announcement Module
Collapse
No announcement yet.
Autowired beans are null in CustomRepositoryImpl Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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

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

    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");
    ...
    	}
    }
    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!
    Last edited by casualconnect; Apr 22nd, 2013, 07:11 AM.
Working...
X