As far as I know there is no annotation equivalent to the following applicationContext.xml
fragment:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd">
<jee:jndi-lookup
id="someDbDataSource"
jndi-name="jdbc/SomeDB"
resource-ref="true" />
...
because it is very easy inject the datasource into your DAOs:
public class SomeDbJdbcDaoSupport {
public static final String SOME_DB_DATA_SOURCE = "someDbDataSource";
private JdbcTemplate jdbcTemplate;
@Autowired
@Qualifier(SOME_DB_DATA_SOURCE)
public void setSomeDbDataSource(DataSource dataSource) {
if (jdbcTemplate == null || dataSource != jdbcTemplate.getDataSource()) {
jdbcTemplate = new JdbcTemplate(dataSource);
}
}
...
Datasource configuration is written into the server configuration files because the server manages a pool of connections, but if you used a different pool manager like c3po you would define datasource properties in spring configuration files avoiding any datasource server configurations.