日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring框架集成mybatis框架的配置(笔记)

發(fā)布時(shí)間:2024/9/5 javascript 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring框架集成mybatis框架的配置(笔记) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.


<!-- 0.注解掃描 -->
<!-- 1.導(dǎo)入外部文件 -->
<!-- 2.數(shù)據(jù)源 -->
<!-- 3.session Factory -->
<!-- 4.事務(wù)模板 -->
<!-- 5.AOP相關(guān)配置 -->
<!-- Mapper掃描 -->

?

<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.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.xsd">

<!-- 0.注解掃描 上下文 構(gòu)成 掃描 -->
<context:component-scan base-package="com.wxzj.crm"></context:component-scan>
<!-- 1.導(dǎo)入外部文件 上下文 屬性 占位 位置-->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 2.數(shù)據(jù)源 ctrl shift T 搜索datasource 告訴spring初始化時(shí)初始化鏈接,銷毀時(shí)關(guān)閉鏈接
同時(shí)需要配置參數(shù),驅(qū)動(dòng)的名字,鏈接,賬號(hào),密碼 name value ${}(在尖括號(hào)里寫)

-->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">


<property name="driverClassName" value="${jdbc.driverClassName}"></property>
<property name="url" value="${jdbc.url}"></property>
<property name="username" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean>
<!-- 3.session Factory mybatis獲取session的工場(chǎng)是SqlSessionFactoryBean
里面需要配置一個(gè)數(shù)據(jù)庫源
和一個(gè) 配置config 源location 指向mybatis的主配置文件
第三個(gè)給每一個(gè)類起一個(gè)別名,這是為啥
找mapper 這次找的是路徑 選擇路徑下的所有mapper (映射)
-->
<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="configLocation" value="classpath:mybatis.cfg.xml"></property>
<property name="typeAliasePackage" value="com.wxzj.crm.domain"></property>
<property name="mapperLocations" value="com/wxzj/crm/mapper/*Mapper.xml"></property>
</bean>
<!-- 事務(wù)管理器 transaction事務(wù)的意思 給他配置數(shù)據(jù)源,讓他在這個(gè)數(shù)據(jù)源上建立事務(wù)-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" >
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 4.事務(wù)模板 他自己沒有事務(wù),得用別人的,這次用阿里巴巴druid 他需要的事務(wù)管理器的名字叫做transaction-manager,默認(rèn)引用

advice: n. 建議;忠告;勸告;通知 -->
<tx:advice id="advice" transaction-manager="transactionManager">
<!-- 配置每一個(gè)方法的專屬配置 attributes 屬性 -->
<tx:attributes>
<tx:method name="get*" read-only="true"/>
<tx:method name="query*" read-only="true"/>
<tx:method name="select*" read-only="true"/>
<tx:method name="list*" read-only="true"/>
<tx:method name="*" />
</tx:attributes>
</tx:advice>
<!-- 5.AOP 切面相關(guān)配置 和事務(wù)一塊使用的,他是面向切面編程的配置
事務(wù)(id=advice)配置的是怎么管理事務(wù),AOP配置的是在哪執(zhí)行事務(wù)
如果只配置事務(wù)不配置aop的話應(yīng)該是沒用的
pointcut切入點(diǎn) execution執(zhí)行-->
<aop:config>
<aop:pointcut expression="execution(* com.xyz.myapp.service.*.*(..))" id="pointCut"/>
<aop:advisor advice-ref="advice" pointcut-ref="pointCut"/>
</aop:config>
<!-- Mapper掃描 配置個(gè)mapper掃描的對(duì)象,讓他去掃描mapper ,這應(yīng)該是spring整合其他框架的手法-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.wxzj.crm.mapper"></property>
</bean>

</beans>

轉(zhuǎn)載于:https://www.cnblogs.com/work396/p/7135999.html

總結(jié)

以上是生活随笔為你收集整理的Spring框架集成mybatis框架的配置(笔记)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。