Quantcast
Channel: Spring Community Forums - Data
Viewing all articles
Browse latest Browse all 297

Autowired beans are null in CustomRepositoryImpl

$
0
0
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!

Viewing all articles
Browse latest Browse all 297

Trending Articles