<?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"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<!--
配置文件:
1.配置数据库连接:
① dataSourse
② sessionFactory
2.事务的配置:
① transactionManager
② tx:advice
③ aop:pointcut
-->
<context:property-placeholder location="classpath:db.properties"/>
<bean id="dataSourse" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="user" value="${jdbc.user}"></property>
<property name="password" value="${jdbc.password}"></property>
<property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
<property name="driverClass" value="${jdbc.driverClass}"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSourse"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<property name="mappingLocations" value="classpath:com/yawn/entity/Acount.hbm.xml"></property>
<!--
以上部分配置来自于 hibernate 的配置文件 hibernate.cfg.xml
如果引入此文件就不需再配置,引入方法如下:
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
-->
</bean>
<!--
配置事务:
1.事务管理器
2.事务属性
3.事务切点
-->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:advice id="txAdvice">
<tx:attributes>
<tx:method name="get*" read-only="true"/>
<tx:method name="*" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut expression="execution(* com.yawn.service.Service1.transfer(..))" id="txPointcut"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>
</aop:config>
<!-- spring 中 bean 的基本配置和属性注入 -->
<bean class="com.yawn.dao.impl.AcountDaoImpl" id="acountDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean class="com.yawn.service.Service1" id="service">
<property name="acountDaoImpl" ref="acountDaoImpl"></property>
</bean>
<!--
<tx:annotation-driven transaction-manager="transactionManager" />
-->
</beans>
以上为整合的配置文件,而整合步骤如下: