<?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:context="http://www.springframework.org/schema/context"
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-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<!-- 配置数据源jdbc-dbcp -->
<!-- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="url" value="jdbc:mysql://localhost:3306/hibernate"></property>
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="username" value="root"></property>
<property name="password" value="rt"></property>
</bean> -->
<!-- 读取jdbc的配置文件 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 配置数据源jdbc-c3p0 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="jdbcUrl" value="${jdbc.url}"></property>
<property name="driverClass" value="${jdbc.driver}"></property>
<property name="user" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>
<!-- spring整合hibernate -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 读取hibernate配置文件 -->
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
<!-- 传入数据源 -->
<property name="dataSource" ref="dataSource"></property>
<!-- hibernate属性(hibernate属性可以放在spring里一般放在hibernate里) -->
<!-- <property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
</props>
</property> -->
<!-- 映射文件 -->
<property name="mappingLocations" value="classpath:com/qf/entity/*.hbm.xml"></property>
</bean>
<!-- spring事物全自动化的 -->
<!-- 事务管理器class换成hibernate的 -->
<bean id="traManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 事物以注解的方式实现 @Transational
<tx:annotation-driven transaction-manager="traManager"/> -->
<!-- 配置事务策略 -->
<tx:advice id="txAdvice" transaction-manager="traManager">
<tx:attributes>
<!-- name:方法名称,支持通配符的
isolation:隔离级别
propagation:事物的转播属性
read-only:是否只读
-->
<tx:method name="tra*" isolation="DEFAULT" propagation="REQUIRED" read-only="false" />
<!-- 查询方法 -->
<tx:method name="get*" read-only="true" />
<tx:method name="find*" read-only="true" />
<tx:method name="query*" read-only="true" />
<!-- 更新操作 -->
<tx:method name="insert*" read-only="false" />
<tx:method name="remo*" read-only="false" />
<tx:method name="update*" read-only="false" />
<tx:method name="del*" read-only="false" />
<tx:method name="add*" read-only="false" />
</tx:attributes>
</tx:advice>
<!-- AOP的配置 -->
<aop:config>
<!-- <aop:pointcut expression="execution(* com.qf.service.*.*(..))" id="p1"/> pointcut-ref="p1" -->
<!-- 事物一般加在service(业务层)层 -->
<aop:advisor advice-ref="txAdvice" pointcut="execution(* com.qf.service.*.*(..))" />
</aop:config>
<!-- service层和dao层的配置 -->
<!-- 注入hibernateTemplate,hibernateTemplate里注入sessionFactory -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="accountDao" class="com.qf.dao.impl.AccountDaoImpl">
<!-- hibernateDaoTemplate里注入hibernateTemplate -->
<property name="hibernateTemplate" ref="hibernateTemplate"></property>
</bean>
<bean id="accountService" class="com.qf.service.impl.AccountServiceImpl">
<property name="accountDao" ref="accountDao"></property>
</bean>
</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
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-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<!-- 配置数据源jdbc-dbcp -->
<!-- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="url" value="jdbc:mysql://localhost:3306/hibernate"></property>
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="username" value="root"></property>
<property name="password" value="rt"></property>
</bean> -->
<!-- 读取jdbc的配置文件 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 配置数据源jdbc-c3p0 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="jdbcUrl" value="${jdbc.url}"></property>
<property name="driverClass" value="${jdbc.driver}"></property>
<property name="user" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>
<!-- spring整合hibernate -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 读取hibernate配置文件 -->
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
<!-- 传入数据源 -->
<property name="dataSource" ref="dataSource"></property>
<!-- hibernate属性(hibernate属性可以放在spring里一般放在hibernate里) -->
<!-- <property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
</props>
</property> -->
<!-- 映射文件 -->
<property name="mappingLocations" value="classpath:com/qf/entity/*.hbm.xml"></property>
</bean>
<!-- spring事物全自动化的 -->
<!-- 事务管理器class换成hibernate的 -->
<bean id="traManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 事物以注解的方式实现 @Transational
<tx:annotation-driven transaction-manager="traManager"/> -->
<!-- 配置事务策略 -->
<tx:advice id="txAdvice" transaction-manager="traManager">
<tx:attributes>
<!-- name:方法名称,支持通配符的
isolation:隔离级别
propagation:事物的转播属性
read-only:是否只读
-->
<tx:method name="tra*" isolation="DEFAULT" propagation="REQUIRED" read-only="false" />
<!-- 查询方法 -->
<tx:method name="get*" read-only="true" />
<tx:method name="find*" read-only="true" />
<tx:method name="query*" read-only="true" />
<!-- 更新操作 -->
<tx:method name="insert*" read-only="false" />
<tx:method name="remo*" read-only="false" />
<tx:method name="update*" read-only="false" />
<tx:method name="del*" read-only="false" />
<tx:method name="add*" read-only="false" />
</tx:attributes>
</tx:advice>
<!-- AOP的配置 -->
<aop:config>
<!-- <aop:pointcut expression="execution(* com.qf.service.*.*(..))" id="p1"/> pointcut-ref="p1" -->
<!-- 事物一般加在service(业务层)层 -->
<aop:advisor advice-ref="txAdvice" pointcut="execution(* com.qf.service.*.*(..))" />
</aop:config>
<!-- service层和dao层的配置 -->
<!-- 注入hibernateTemplate,hibernateTemplate里注入sessionFactory -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="accountDao" class="com.qf.dao.impl.AccountDaoImpl">
<!-- hibernateDaoTemplate里注入hibernateTemplate -->
<property name="hibernateTemplate" ref="hibernateTemplate"></property>
</bean>
<bean id="accountService" class="com.qf.service.impl.AccountServiceImpl">
<property name="accountDao" ref="accountDao"></property>
</bean>
</beans>