我的 Web 应用程序使用 Spring 3.1.2 和 Hibernate 4.1.7。我现在想配置这两个。我有我的hibernate.cfg.xml
文件:
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="hibernate.connection.autocommit">false</property>
<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<!--
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
-->
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
</session-factory>
</hibernate-configuration>
我的webapp-servlet.xml
弹簧配置文件:
<beans>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="configLocation">
<value>
classpath:hibernate.cfg.xml
</value>
</property>
<property name = "dataSource" ref = "dataSource"></property>
</bean>
<bean id = "dataSource" class = "org.apache.commons.dbcp.BasicDataSource">
<property name = "driverClassName" value = "com.mysql.jdbc.Driver" />
<property name = "url" value = "jdbc:mysql://localhost:3306/test" />
<property name = "username" value = "root" />
<property name = "password" value = "root" />
<property name = "maxActive" value = "10" />
</bean>
</beans>
- 当所有需要的数据都已经包含在 hibernate 配置文件中时,为什么我需要配置一个 DataSource bean?Hibernate 是否有一些可以使用的默认值?
- 还有哪些
DataSource
我可以使用的? - 我是否缺少任何其他 bean 或配置参数/属性来让 hibernate 与我的应用程序一起工作?