<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 指定Hibernate的配置文件的位置 -->
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
<!-- 配置DataSource -->
<property name="dataSource">
<bean class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- 数据库连接信息 -->
<property name="jdbcUrl" value="${jdbcUrl}"></property>
<property name="driverClass" value="${driverClass}"></property>
<property name="user" value="${username}"></property>
<property name="password" value="${password}"></property>
<!-- 其他一些配置 -->
<property name="initialPoolSize" value="${initialPoolSize}"></property>
<property name="minPoolSize" value="${minPoolSize}"></property>
<property name="maxPoolSize" value="${maxPoolSize}"></property>
<property name="acquireIncrement" value="${acquireIncrement}"></property>
<property name="maxStatements" value="${maxStatements}"></property>
<property name="maxStatementsPerConnection" value="${maxStatementsPerConnection}"></property>
<property name="maxIdleTime" value="${maxIdleTime}"></property>
</bean>
</property>
</bean>
* dataSource这个bean是个内部bean,所以这个bean不需要id,这个bean只能给sessionFactory这个bean用
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 指定Hibernate的配置文件的位置 -->
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
<!-- 配置DataSource -->
<property name="dataSource" ref="dataSource"></property>
</bean>
* 如果把dataSource放在外面,则大家都可以使用这个bean