本章介绍Mybatis与Spring整合的mybatis-spring.jar的编译,阅读本章前,现看

  【Spring】Spring源码编译 和 【Mybatis】MyBatis源码编译

环境准备

  • Maven:3.6.3
  • Jdk:1.8.0_181
  • idea

1、下载mybatis-spring源码

  官网地址:https://github.com/mybatis/spring

  选择需要的版本下载,本例下载的是 mybatis-spring-2.0.1,下载完后解压。打开pom.xml,查看mybatis的依赖的父工程版本

  【Mybatis】mybatis-spring源码编译

2、下载载mybatis-parent源码

  选择mybatis对应的mybatis-parent版本,本例版本是 mybatis-parent-31

  官网地址:https://github.com/mybatis/parent

  【Mybatis】mybatis-spring源码编译

3、源码导入Idea

  在Idea中新建一个空项目,将 mybatis-spring 、 mybatis-parent 都放到空项目下,并导入模块

  本例直接放在上一章(【Mybatis】MyBatis源码编译) mybatis 源码目录中

  【Mybatis】mybatis-spring源码编译

4、编译mybatis-parent源码,编译mybatis源码

1、编译mybatis-parent项目

  切换mybatis-parent项目: 

  命令:mvn clean install

2、编译mybatis-spring项目

  切换mybatis-spring项目(可以修改一下版本号,修改成自己特有的版本,方便区分): 

  修改mybatis-spring版本(2.0.1-MY)。避免与官网依赖相同版本

  命令:mvn install -Dmaven.test.skip=true

5、测试使用源码

运行mybatis-spring项中的测试类

  org.mybatis.spring.SqlSessionFactoryBeanTest.java#testDefaults()

  【Mybatis】mybatis-spring源码编译

  运行成功,说明已经编译好了

6、Demo使用源码

1、安装 mybatis源码 和 mybatis-spring 源码

  将项目中 mybatis源码(使用自己的版本号: 3.5.1-MY) 和 mybatis-spring 源码(使用自己的版本号: 2.0.1-MY),

  安装的maven仓库中,这样其他项目引用你编译的源码就能看到其中的注释

    使用Maven插件:maven-source-plugin

<!-- 生成sources源码包的插件 -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <version>3.2.1</version>
    <configuration>
        <attach>true</attach>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>jar-no-fork</goal>
            </goals>
        </execution>
    </executions>
</plugin>

 

  使用命令:mvn install

  【Mybatis】mybatis-spring源码编译

2、在Spring源码目录中新建测试项目

  项目参考:【Spring】Spring源码编译

  【Mybatis】mybatis-spring源码编译

  1、spring-my-mybatis.gradle,gradle配置文件如下:引入自己编译的 mybatis源码 和 mybatis-spring 源码

description = "Spring MY MYBATIS"

apply plugin: "kotlin"

dependencies {
    compile "mysql:mysql-connector-java:8.0.12"
    compile "com.alibaba:druid:1.1.8"

    compile "org.mybatis:mybatis:3.5.1-MY"
    compile "org.mybatis:mybatis-spring:2.0.1-MY"


    compile "ognl:ognl:3.2.15"
    compile "org.javassist:javassist:3.27.0-GA"

    compile(project(":spring-core"))
    optional(project(":spring-aop"))
    optional(project(":spring-beans"))
    optional(project(":spring-context"))
    optional(project(":spring-jdbc"))
    optional(project(":spring-orm"))
    optional(project(":spring-tx"))
}
View Code

相关文章: