<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> <!-- bean里配置数据源,里面配置连接驱动、字符串、用户名、密码,需要导入两个包commons-pool.jar和commons-dbcp.jar-->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>oracle.jdbc.OracleDriver</value>
</property>
<property name="url">
<value>jdbc:oracle:thin:@localhost:1521:orcl</value>
</property>
<property name="username">
<value>myuser</value>
</property>
<property name="password">
<value>u123</value>
</property>
</bean>

<!-- 配置sessionFactory 引入本地(上方的)dataSource数据源 -->
<bean id="sessionFactory" 
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<!-- 配置实体映射文件 -->
<property name="mappingResources">
<list>
<value>com/test/po/PersonBean.hbm.xml</value>
<!--  可配置多个value代表多个实体bean映射文件 -->
</list>
</property>
</bean>
<!-- 实现类引入sessionFactory -->
<bean id="personDao" class="com.test.dao.impl.PersonDAOImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean></beans>

解决方案 »

  1.   

    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource">
    <ref bean="dataSource" />
    </property>
    <!-- annotation org.hibernate.dialect.SQLServerDialect-->
    <property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">
    org.hibernate.dialect.MySQL5InnoDBDialect
    </prop>
    <prop key="hibernate.hbm2ddl.auto">update</prop>
    <prop key="hibernate.format_sql">true</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.cache.use_second_level_cache">true</prop>
    <prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProvider
    </prop>
    <prop key="hibernate.cache.use_query_cache">true</prop>
    <!-- hibernate search support property -->
    <prop key="hibernate.search.default.directory_provider">
    org.hibernate.search.store.FSDirectoryProvider
    </prop>
    </props>
    </property>