<!-- 0.注解扫描 -->
<!-- 1.导入外部文件 -->
<!-- 2.数据源 -->
<!-- 3.session Factory -->
<!-- 4.事务模板 -->
<!-- 5.AOP相关配置 -->
<!-- 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.注解扫描 上下文 构成 扫描 -->
<context:component-scan base-package="com.wxzj.crm"></context:component-scan>
<!-- 1.导入外部文件 上下文 属性 占位 位置-->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 2.数据源 ctrl shift T 搜索datasource 告诉spring初始化时初始化链接,销毁时关闭链接
同时需要配置参数,驱动的名字,链接,账号,密码 name value ${}(在尖括号里写)

-->
<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的工场是SqlSessionFactoryBean
里面需要配置一个数据库源
和一个 配置config 源location 指向mybatis的主配置文件
第三个给每一个类起一个别名,这是为啥
找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>
<!-- 事务管理器 transaction事务的意思 给他配置数据源,让他在这个数据源上建立事务-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" >
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 4.事务模板 他自己没有事务,得用别人的,这次用阿里巴巴druid 他需要的事务管理器的名字叫做transaction-manager,默认引用

advice: n. 建议;忠告;劝告;通知 -->
<tx:advice id="advice" transaction-manager="transactionManager">
<!-- 配置每一个方法的专属配置 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 切面相关配置 和事务一块使用的,他是面向切面编程的配置
事务(id=advice)配置的是怎么管理事务,AOP配置的是在哪执行事务
如果只配置事务不配置aop的话应该是没用的
pointcut切入点 execution执行-->
<aop:config>
<aop:pointcut expression="execution(* com.xyz.myapp.service.*.*(..))" id="pointCut"/>
<aop:advisor advice-ref="advice" pointcut-ref="pointCut"/>
</aop:config>
<!-- Mapper扫描 配置个mapper扫描的对象,让他去扫描mapper ,这应该是spring整合其他框架的手法-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.wxzj.crm.mapper"></property>
</bean>

</beans>

Spring框架集成mybatis框架的配置(笔记)的更多相关文章

  1. spring boot集成mybatis框架

    概述 中文官网:http://www.mybatis.cn 参考教程:https://www.w3cschool.cn/mybatis MyBatis Plus:http://mp.baomidou. ...

  2. spring如何集成第三方框架? 比如mybatis

    实体Bean的创建: 1: 基于class构建, 2: 构造方法构建 3: 静态工厂方法创建 4: FactoryBean构建 spring如何集成第三方框架? 比如mybatis 在mybatis中 ...

  3. Spring Boot 数据访问集成 MyBatis 与事物配置

    对于软件系统而言,持久化数据到数据库是至关重要的一部分.在 Java 领域,有很多的实现了数据持久化层的工具和框架(ORM).ORM 框架的本质是简化编程中操作数据库的繁琐性,比如可以根据对象生成 S ...

  4. flink 流式处理中如何集成mybatis框架

    flink 中自身虽然实现了大量的connectors,如下图所示,也实现了jdbc的connector,可以通过jdbc 去操作数据库,但是flink-jdbc包中对数据库的操作是以ROW来操作并且 ...

  5. 整合Spring框架和MyBatis框架

    ------------------------siwuxie095                                 整合 Spring 框架和 MyBatis 框架         ...

  6. spring boot集成mybatis(3) - mybatis generator 配置

    Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...

  7. Spring Boot集成MyBatis开发Web项目

    1.Maven构建Spring Boot 创建Maven Web工程,引入spring-boot-starter-parent依赖 <project xmlns="http://mav ...

  8. 详解Spring Boot集成MyBatis的开发流程

    MyBatis是支持定制化SQL.存储过程以及高级映射的优秀的持久层框架,避免了几乎所有的JDBC代码和手动设置参数以及获取结果集. spring Boot是能支持快速创建Spring应用的Java框 ...

  9. SpringBoot集成MyBatis的Bean配置方式

    SpringBoot集成MyBatis的Bean配置方式 SpringBoot是一款轻量级开发的框架,简化了很多原先的xml文件配置方式,接下来就介绍一下如何不适用XML来配置Mybatis spri ...

随机推荐

  1. PHP提取字符串中的所有汉字

    <?php $str = 'aiezu.com 爱E族, baidu.com 百度'; preg_match_all("#[\x{4e00}-\x{9fa5}]#u", $s ...

  2. css里面position:relative与position:absolute的区别

    position:absolute这个是绝对定位:是相对于浏览器的定位.比如:position:absolute:left:20px;top:80px; 这个容器始终位于距离浏览器左20px,距离浏览 ...

  3. 你应该知道的jQuery技巧【收藏】

    jQuery的存在,让学习前端开发的人感到前端越来越容易入门了,用简单的几行代码就可以实现需求,但是,你真的会用jQuery么,当代码运行 后无法看到自己预期的效果,是不是觉得jQuery出了问题,其 ...

  4. Struts2之初识篇(一)——与struts的区别和基本配置

    Struts2资源下载地址: Struts官方地址:http://struts.apache.org/ 我这里下载了struts2的最新版本struts2-2.5.10.1-all.所有内容如下图: ...

  5. win32SDK的hello,world程序

    首次用Code::Blocks写Win32GUI程序,关于GDI+的引用摸索了半天.SDK写GUI比较累人,以后还是考虑Qt或者其他方式. 代码: /** *code by lichmama from ...

  6. centos7安装图形化界面

    yum groups install -y "GNOME Desktop" "Graphical Administration Tools"

  7. JavaWeb 后端 <四> 之 Cookie HttpSession 学习笔记

    一.会话管理概述 1.什么是会话? 好比一次通话.打开浏览器,点击多次链接(发出多次请求和收到多次的响应),关闭浏览器,这个过程就是一次会话. 有功能 可以  文件 新建会话 2.解决的问题是什么? ...

  8. Akka(13): 分布式运算:Cluster-Sharding-运算的集群分片

    通过上篇关于Cluster-Singleton的介绍,我们了解了Akka为分布式程序提供的编程支持:基于消息驱动的运算模式特别适合分布式程序编程,我们不需要特别的努力,只需要按照普通的Actor编程方 ...

  9. spring boot 事件发布与接收

    1.创建发布对象 LoginEvent 2.在要发布对象的地方注入 ApplicationEventPublisher @Autowired ApplicationEventPublisher pub ...

  10. 【MySQL故障处理】 Seconds_Behind_Master= NULL Error_code: 1197

    版本:mysql 5.6.32**错误描述:**```Error_code: 1197Last_Error: Worker 3 failed executing transaction '352aa3 ...