I have three interfaces going together a CsvParser
, DboMapper
and a CrudRepository
. Now I have like 100 implementations of each of those and I want to wire them into a Map using beans.xml. Then whatever file I get I just ask for the corresponding parser, mapper and repository to do the job.
<context:component-scan base-package="xxx" />
<jpa:repositories base-package="xxx" />
<util:map id="loaders" map-class="java.util.HashMap">
<entry key="account-list.csv"><ref bean="accountListLoader" /></entry>
<!-- more to come -->
</util:map>
<bean id="accountListLoader" class="xxx.etl.CsvFileLoader">
<constructor-arg index="0">
<bean class="xxx.model.implementations.accountlist.AccountListCsvParser" />
</constructor-arg>
<constructor-arg index="1">
<bean class="xxx.model.implementations.accountlist.AccountListMapper"/>
</constructor-arg>
<constructor-arg index="2">
<bean class="xxx.model.implementations.accountlist.AccountListRepositoryImpl" />
</constructor-arg>
</bean>
However the last bean is actually a CrudRepository and thus an interface which can not be instantiated. Can I somehow hand wire a JPA (mysql) repository?
Or is the a way to @Autowire
something like that? I mean auto wiring tens of implementations of an interface into a map?