ssm整合之Spring整合MyBatis框架配置事務(wù)

1.在applicationContext.xml修改代碼如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="/tupian/20230522/"
xmlns:xsi="/tupian/20230522/XMLSchema-instance"
xmlns:context="/tupian/20230522/"
xmlns:aop="/tupian/20230522/"
xmlns:tx="/tupian/20230522/"
xsi:schemaLocation="http://www.springframework.org/schema/beans
/tupian/20230522/spring-beans.xsd
http://www.springframework.org/schema/context
/tupian/20230522/spring-context.xsd
http://www.springframework.org/schema/aop
/tupian/20230522/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--開啟注解的掃描,希望處理service和dao,controller不需要Spring框架去處理-->
<context:component-scan base-package="com.txw">
<!--配置哪些注解不掃描-->
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<!--Spring整合MyBatis框架-->
<!--配置連接池-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql:///ssm"/>
<property name="user" value="root"/>
<property name="password" value="123456"/>
</bean>
<!--配置SqlSessionFactory工廠-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
</bean>
<!--配置AccountDao接口所在包-->
<bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.txw.dao"/>
</bean>
<!--配置Spring框架聲明式事務(wù)管理-->
<!--配置事務(wù)管理器-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!--配置事務(wù)通知-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="find*" read-only="true"/>
<tx:method name="*" isolation="DEFAULT"/>
</tx:attributes>
</tx:advice>
<!--配置AOP增強(qiáng)-->
<aop:config>
<aop:advisor advice-ref="txAdvice" pointcut="execution(* com.txw.service.impl.*ServiceImpl.*(..))"/>
</aop:config>
</beans>
網(wǎng)站名稱:ssm整合之Spring整合MyBatis框架配置事務(wù)的詳細(xì)教程-創(chuàng)新互聯(lián)
網(wǎng)頁鏈接:http://chinadenli.net/article22/ddpgcc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計(jì)、營銷型網(wǎng)站建設(shè)、網(wǎng)站排名、靜態(tài)網(wǎng)站、品牌網(wǎng)站建設(shè)、移動(dòng)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容