http://www.blogjava.net/pitey/archive/2008/03/05/183932.html
applicationContext.xml里面设置
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean" lazy-init="default" autowire="default" dependency-check="default">
<property name="jndiName">
<value>JDBC/TEST</value>
</property>
</bean> 或者
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url" value="jdbc:oracle:thin:@127.0.0.1:1521:ora"></property>
<property name="username" value="test"></property>
<property name="password" value="123456"></property>
</bean>
通过DataSourceUtils.getConnection(DataSource);就能获取到设置的DataSource 然后获得connection
public static Connection getConnection()
throws SQLException
{
return DataSourceUtils.getConnection((DataSource)ServiceLocator.getBean("dataSource"));
}