Annotation-based DI of multiple JNDI resources
My application uses two data sources (container managed) exposed to the Spring container via jee-jndi-lookup. The two data sources are used by separate hierarchy of @Repository and @Service components. Since I am trying to keep my Spring configuration files lean with the use of annotations, I ended up being unsure about how the data sources will be wired to their respective @Repository components.
The relevant snippet from my Spring configuration file:
Code:
<context:annotation-config />
<context:component-scan base-package="my.package" />
<jee:jndi-lookup id="omsData"
jndi-name="jdbc/omsDB"
resource-ref="true"
proxy-interface="javax.sql.DataSource" />
<jee:jndi-lookup id="corpData"
jndi-name="jdbc/corpDB"
resource-ref="true"
proxy-interface="javax.sql.DataSource" />
Here is how I am trying to get the DI magic to manifest in the respective DAO component implementations:
OMSRepositoryJdbcImpl
Code:
@Repository
public class OMSRepositoryJdbcImpl implements IOMSRepository {
private JdbcTemplate OMSRepositoryTemplate;
@Autowired
public OMSRepositoryJdbcImpl(DataSource omsData) {
this.OMSRepositoryTemplate= new JdbcTemplate(omsData);
}
}
CorpRepositoryJdbcImpl
Code:
@Repository
public class CorpRepositoryJdbcImpl implements ICorpRepository {
private JdbcTemplate CorpRepositoryTemplate;
@Autowired
public CorpRepositoryJdbcImpl(DataSource corpData) {
this.CorpRepositoryTemplate= new JdbcTemplate(corpData);
}
}
If I had defined the data sources using standard <bean /> declarations, I would have used the following attribute to direct the DI magic.
But the <jee:jndi-lookup /> declaration does not seem to facilitate this control. How can I ensure that the two data sources are DI'd into the respective @Repository components correctly?
Thanks!
Ashwin