日期:2014-05-20 浏览次数:20786 次
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <!-- 开启组建自动扫描技术,会扫描base-package中所有文件以及其子包的所有文件 --> <context:component-scan base-package="service,action"/> <!-- 定义数据源,采用默认的单例模式 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://127.0.0.1:3306/test"/> <property name="username" value="root"/> <property name="password" value="root"/> </bean> <!-- 定义sessionFactory,采用默认的单例模式 --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="hibernateProperties"> <props> <!-- 设置方言 --> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </prop> <!-- 格式化输出的sql语句(可选) --> <prop key="hibernate.format_sql"> true </prop> <!-- 是否打印sql语句 --> <prop key="hibernate.show_sql"> false </prop> <!-- 配置二级缓存 --> <prop key="hibernate.cache.use_second_level_cache"> true </prop> <!-- 由于查询的缓存命中率很低,所以我们关掉查询时的二级缓存 --> <prop key="hibernate.cache.use_query_cache"> false </prop> <!-- 配置二级缓存的相应的类 --> <prop key="hibernate.cache.provider_class"> org.hibernate.cache.EhCacheProvider </prop> </props> </property> <property name="mappingResources"> <list> <value>bean/Person.hbm.xml</value> </list> </property> </bean> <!-- 定义spring事务管理器 --> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <!-- 将sessionfactory交给spring管理事务 --> <tx:annotation-driven transaction-manager="txManager"/> </beans>