几种数据源
Test:
***********************************************************************************************************************
1 <!-- 1.dao --> 2 <bean id="bookDao" class="cn.happy.dao.impl.BookDAOImpl"> 3 <!-- <property name="jdbcTemplate" ref="myJDBCTemplate"></property> --> 4 <property name="dataSource" ref="dataSource"></property> 5 </bean> 6 7 <!-- 2.service --> 8 <bean id="bookService" class="cn.happy.service.impl.BookServiceImpl"> 9 <property name="dao" ref="bookDao"></property> 10 </bean> 11 12 <!-- c3p0数据源 --> 13 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> 14 <property name="driverClass" value="${jdbc.driver}"></property> 15 <property name="jdbcUrl" value="${jdbc.url}"></property> 16 <property name="user" value="${jdbc.username}"></property> 17 <property name="password" value="${jdbc.password}"></property> 18 </bean> 19 20 <!-- 4.注册jdbc属性 --> 21 <context:property-placeholder location="classpath:jdb.properties"/> 22 23 <!-- 5.注册jdbcTemplate --> 24 <!-- <bean id="myJDBCTemplate" class="org.springframework.jdbc.core.JdbcTemplate"> 25 <property name="dataSource" ref="dataSource"></property> 26 </bean> --> 27 28 <!-- 3.注册数据源 spring --> 29 <!-- <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 30 <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> 31 <property name="url" value="jdbc:mysql:///BookShop"></property> 32 <property name="username" value="root"></property> 33 <property name="password" value="root"></property> 34 </bean> --> 35 36 <!-- 3.注册数据源 dbcp --> 37 <!-- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> 38 <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> 39 <property name="url" value="jdbc:mysql:///BookShop"></property> 40 <property name="username" value="root"></property> 41 <property name="password" value="root"></property> 42 </bean> --> 43 44 45 46 <!-- 4.注册jdbc属性 --> 47 <!-- <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 48 <property name="location" value="classpath:jdb.properties"></property> 49 </bean> -->
<!-- 1.dao --> <bean id="bookDao" class="cn.happy.dao.impl.BookDAOImpl"></bean> <!-- 2.service --> <bean id="bookService" class="cn.happy.service.impl.BookServiceImpl"> <property name="dao" ref="bookDao"></property> </bean>