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

     2022-03-19     647

关键词:


<!-- 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框架学习笔记---[spring框架整合mybatis框架](代码片段)

文章目录Spring框架整合Mybatis框架(1)导入需要使用的maven包(2)实体类,数据访问层,服务层,以及数据访问映射文件📢创建实体类Person📢数据访问接口PersonMapper📢服务层PersonService📢数据访问映射文件PersonMapper.xml(3)不... 查看详情

怎么查看javaweb项目的框架?

...常,必须将一些配置文件添加到框架集成中。例如,框架spring将具有一系列文件,例如spring。而mybatis框架将有许多*.xml文件。您可以查看正在使用的配置文件,以了解正在使用的框架。 参考技术B查看JavaWeb使用的框架的最简单方... 查看详情

spring集成mybatis框架(环境详细配置)(代码片段)

目录配置pom.xml配置文件配置spring.xml配置Mybatis.xml配置log4j.properties配置pom.xml配置文件<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0" 查看详情

spring集成mybatis框架(环境详细配置)(代码片段)

目录配置pom.xml配置文件配置spring.xml配置Mybatis.xml配置log4j.properties配置pom.xml配置文件<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0" 查看详情

spring+springmvc+mybatis框架集成搭建教程二(依赖配置及框架整合)

依赖导入以及框架整合(1).打开项目的pom.xml文件,声明依赖<projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0http://ma 查看详情

spring集成mybatis3

0说明Mybatis使用 MyBatis-Spring 类库来集成spring框架 MyBatis-Spring官网 http://www.mybatis.org/spring/index.htmlMyBatis-Spring是一个MyBatis框架的子模块,可以提供和Spring框架的无缝集成。它可以是Mybatis利用Spring来实现事务管理,使... 查看详情

spring+springmvc+mybatis框架集成搭建教程

一、背景  最近有很多同学由于没有过SSM(Spring+SpringMvc+Mybatis,以下简称SSM)框架的搭建的经历,所以在自己搭建SSM框架集成的时候,出现了这样或者那样的问题,很是苦恼,网络上又没有很详细的讲解以及搭建的教程。闲来无事... 查看详情

spring集成mybatis框架(环境详细配置)(代码片段)

目录配置pom.xml配置文件配置spring.xml配置Mybatis.xml配置log4j.properties配置pom.xml配置文件<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instanc... 查看详情

springspring集成mybatis(代码片段)

集成思路Spring能集成很多的框架,是Spring一个优势功能。通过集成功能,让开发人员使用其他框架更方便。集成使用的是SpringIoC核心技术。要使用框架,例如mybatis,怎么使用mybatis?Spring集成MyBatis的目的👉... 查看详情

spring+springmvc+mybatis框架集成搭建教程四(项目部署及测试)

在IDEA中将项目部署到本地Tomcat下进行运行并验证整合结果(1).点击如下图所示的下拉按钮,弹出EditConfigurations...后点击该项。 (2).跳出如下界面后,点击红框内的"+"号,选择TomcatServer->Local (3).出现以下界面,修改自定义启动... 查看详情

ssmspring集成mybatis(代码片段)

Spring框架集成Mybtis为啥学习集成MybatisORM框架实现步骤为啥学习集成MybatisORM框架虽然Spring中提供了JDBCTemplate模块,已经很大程度了解决了JDBC代码的复杂度,但它仍然是和Java代码写在一起的。反观Mybatis将Sql语句写在配置文... 查看详情

spring+springmvc+mybatis框架集成搭建教程一(背景介绍及项目创建)

一、背景  最近有很多同学由于没有过SSM(Spring+SpringMvc+Mybatis,以下简称SSM)框架的搭建的经历,所以在自己搭建SSM框架集成的时候,出现了这样或者那样的问题,很是苦恼,网络上又没有很详细的讲解以及搭建的教程。闲来无事... 查看详情

mybatis框架学习笔记(代码片段)

本篇Mybatis框架学习笔记;紧跟之前的学习Mybatis框架学习笔记(2)—>在mybatis框架核心配置文件中需要学习的配置configuration(配置)properties(属性)settings(设置)typeAliases(类型别名)typeHandlers 查看详情

mybatis框架学习笔记(代码片段)

本篇Mybatis框架学习笔记;紧跟之前的学习Mybatis框架学习笔记(1)—>小智RE0在mybatis框架核心配置文件中需要学习的配置configuration(配置)properties(属性)settings(设置)typeAliases(类型别名)typeHandl... 查看详情

框架整合——spring与mybatis框架整合

Spring整合MyBatis1.整合Spring【整合目标:在spring的配置文件中配置SqlSessionFactory以及让mybatis用上spring的声明式事务】1).加入Spring的jar包和配置文件<1>、Spring框架需要的jar包:com.springsource.net.sf.cglib-2.2.0.jarcom.springsource.org.aopal 查看详情

sprig框架集成(ssm框架)|sping+springmvc+mybatis(代码片段)

SSM框架SSM是sping+springMVC+mybatis集成的框架:标准的MVC模式,整个系统划分为表现层,controller层,service层,DAO层四层Spring(业务层)Spring就像是整个项目中装配bean的大工厂,在配置文件中可以... 查看详情

持久化框架springmvc+spring4+mybatis3集成,开发简单web项目+源码下载

...我们介绍了mybatis的基本概念与原理,这篇博文我们通过Spring与Mybatis集成,开发一个简单用户增删改查的Web项目。 基本准备工作 1、安装JDK1.6以上版本,安装与配置2、下载mybatis-3.2.0版:https://repo1.maven.org/maven2/org/mybatis/myb... 查看详情

ssm框架专题-mybatis框架从零入门老杜版笔记(上)(代码片段)

MyBatis框架从零入门老杜版笔记(上)一、MyBatis概述1.1框架framework1.2MyBatis和JDBC的关系1.3JDBC不足1.4了解MyBatis1.5了解ORM二、MyBatis入门程序2.1建数据库表2.2加载mybatis的五个步骤2.3MyBatis中的事务2.4编写MyBatis代码2.5在MyBatis中引... 查看详情