<?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"/>
<!-- 開啓包掃描 -->
<context:component-scan base-package="com.qf.*"></context:component-scan>
<!-- 配置數據源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整合mybatis -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 注入數據源 -->
<property name="dataSource" ref="dataSource"></property>
<!-- mybatis配置文件 -->
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
<!-- 設置別名 -->
<property name="typeAliasesPackage" value="com.qf.entity"></property>
<!-- mapper文件 -->
<!-- <property name="mapperLocations" value="com/qf/mapper/*.xml" /> -->
</bean>
<!-- spring事物全自動化的 -->
<!-- 事務管理器class換成hibernate的 -->
<bean id="traManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></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>
<!-- 自動創建的dao層的實現類 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 指定mapper接口文件所在的基包 -->
<property name="basePackage" value="com.qf.dao"></property>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></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"/>
<!-- 開啓包掃描 -->
<context:component-scan base-package="com.qf.*"></context:component-scan>
<!-- 配置數據源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整合mybatis -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 注入數據源 -->
<property name="dataSource" ref="dataSource"></property>
<!-- mybatis配置文件 -->
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
<!-- 設置別名 -->
<property name="typeAliasesPackage" value="com.qf.entity"></property>
<!-- mapper文件 -->
<!-- <property name="mapperLocations" value="com/qf/mapper/*.xml" /> -->
</bean>
<!-- spring事物全自動化的 -->
<!-- 事務管理器class換成hibernate的 -->
<bean id="traManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></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>
<!-- 自動創建的dao層的實現類 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 指定mapper接口文件所在的基包 -->
<property name="basePackage" value="com.qf.dao"></property>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
</beans>