Spring中四个数据源

 <!-- ********* Spring中四个数据源 ********* -->

	<!-- DBCP数据源 -->
	<bean name="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
		<property name="url" value="jdbc:oracle:thin:@localhost:1521:oracle"/>
		<property name="username" value="fantasy"/>
		<property name="password" value="fantasy"/>
	</bean>

	<!-- C3P0数据源 -->
	<bean name="c3p0DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
		<property name="driverClass" value="oralce.jdbc.driver.OracleDriver"/>
		<property name="jdbcUrl" value="jdbc:oracle:thin:@localhost:1521:oracle"/>
		<property name="user" value="fantasy"/>
		<property name="password" value="fantasy"/>
	</bean>

 <!-- Spring数据源 -->
	<bean name="springDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="driverClassName" value="oralce.jdbc.driver.OracleDriver"/>
		<property name="url" value="jdbc:oracle:thin:@localhost:1521:oracle"/>
		<property name="username" value="fantasy"/>
		<property name="password" value="fantasy"/>
	</bean>

 <!-- 创建模板 -->
	<bean name="jndiTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
		<property name="dataSource" ref="dataSource"/>
		</bean>
		<bean name="userDaoImpl" class="com.gmd.dao.impl.UserDaoImpl">
		<property name="template" ref="jdbcTemplate"/>
		</bean>

	<!-- JDNI数据源,需要启动tomcat -->
	<bean name="jndiDataSource"
		class="org.springframework.jndi.JndiObjectFactoryBean">
		<property name="jndiName" value="java:comp/env/jdbc/oracle"/>
	</bean>

你可能感兴趣的:(java,spring,tomcat)