<?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:util="http://www.springframework.org/schema/util" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-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/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>/WEB-INF/config/jdbc.properties</value> </list> </property> </bean> <!-- 数据源 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> <property name="initialSize" value="5" /> <property name="maxActive" value="100" /> <property name="maxIdle" value="30" /> <property name="maxWait" value="1000" /> <property name="poolPreparedStatements" value="true" /> <property name="defaultAutoCommit" value="false" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="mappingResources"> <list> <value>com/yuanhai/pojo/Admin.hbm.xml</value> <value>com/yuanhai/pojo/Contactway.hbm.xml</value> <value>com/yuanhai/pojo/Freephne.hbm.xml</value> <value>com/yuanhai/pojo/HelpInfo.hbm.xml</value> <value>com/yuanhai/pojo/IndexClass.hbm.xml</value> <value>com/yuanhai/pojo/Pictures.hbm.xml</value> <value>com/yuanhai/pojo/Scheme.hbm.xml</value> <value>com/yuanhai/pojo/Subclass.hbm.xml</value> <value>com/yuanhai/pojo/SubclassInfo.hbm.xml</value> <value>com/yuanhai/pojo/SuclssInfoContent.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> </props> </property> </bean> <!-- 数据库访问的基类 --> <bean id="baseDao" class="com.yuanhai.utils.BaseDao"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- 事务相关配置 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <tx:advice id="adv" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="remove*" propagation="REQUIRED" /> <tx:method name="modif*" propagation="REQUIRED" /> <tx:method name="*" propagation="SUPPORTS" read-only="true" /> </tx:attributes> </tx:advice> <aop:config> <aop:advisor advice-ref="adv" pointcut="execution(public * com.yuanhai.biz.*.*(..))" /> </aop:config> <!-- 其它资源文件引入--> <import resource="config/spring/system.xml" /> </beans>
网上全面文章
http://blog.csdn.net/ayan117/archive/2010/07/20/5748134.aspx