本文是作者原创,版权归作者所有.若要转载,请注明出处

下载spring源码,本文用的是版本如下:

springframework 5.1.x,   IDE工具idea 2019.2.3    JAVA版本 jdk1.8.0_171    构建工具gradle-4.9

1.下载springframework 5.1.x源码

2.解压下载的压缩包,在已有工程中导入该项目

3.选择该项目路径

4.选择gradle导入

5.等待它自己构建

6.编译完,有个弹框出现,点击ok

7.如图,设置gradle配置

8.先编译spring-core模块

9.编译成功

我们可以看到,多了存放字节码文件的build文件夹

10.编译spring-oxm模块,和上面一样

11.忽略spring-aspects模块

12.编译整个spring模块

13.放开spring-aspects模块,并编译

14.新建一个测试模块,测试spring是否编译成功

点击,右上角的ok

加上以下代码

//spring core
compile(project(":spring-context"))
//spring 对web的支持
compile(project(":spring-webmvc"))
//连接池
compile(project(":spring-jdbc"))
//mybatis core
compile group: 'org.mybatis', name: 'mybatis', version: '3.5.0' //源码 spring mybaits的插件包
compile group: 'org.mybatis', name: 'mybatis-spring', version: '2.0.0' //db
compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.6' //tomcat 容器
compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-core', version: '8.5.5'
// jsp
compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-jasper', version: '8.5.5'
// https://mvnrepository.com/artifact/com.alibaba/fastjson
compile group: 'com.alibaba', name: 'fastjson', version: '1.2.50'
// https://mvnrepository.com/artifact/org.aspectj/aspectjweaver
compile group: 'org.aspectj', name: 'aspectjweaver', version: '1.9.0'

最后build.gradle文件内容如下

plugins {
id 'java'
} group 'org.springframework'
version '5.1.10.BUILD-SNAPSHOT' sourceCompatibility = 1.8 repositories {
mavenCentral()
} dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
//spring core
compile(project(":spring-context"))
//spring 对web的支持
compile(project(":spring-webmvc"))
//连接池
compile(project(":spring-jdbc"))
//mybatis core
compile group: 'org.mybatis', name: 'mybatis', version: '3.5.0'
//源码 spring mybaits的插件包
compile group: 'org.mybatis', name: 'mybatis-spring', version: '2.0.0'
//db
compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.6'
//tomcat 容器
compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-core', version: '8.5.5'
// jsp
compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-jasper', version: '8.5.5'
// https://mvnrepository.com/artifact/com.alibaba/fastjson
compile group: 'com.alibaba', name: 'fastjson', version: '1.2.50'
// https://mvnrepository.com/artifact/org.aspectj/aspectjweaver
compile group: 'org.aspectj', name: 'aspectjweaver', version: '1.9.0'
}

15.编写demo

package demo01;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class HelloSpring { private String input_str = null; public String getMyStr() {
return this.input_str;
} public void setMyStr(String strParam) {
this.input_str = strParam;
} public void Print() {
System.out.println("Hello," + this.getMyStr());
} public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
HelloSpring helloSpring = (HelloSpring) context.getBean("myFirstSpringDemo");
helloSpring.Print(); } }

xml配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd"
default-autowire="byType"> <bean id="myFirstSpringDemo" class="demo01.HelloSpring">
<property name="myStr">
<value>I am Spring</value>
</property>
</bean>
</beans>

16.运行,报错

可以看到错误信息提示我们在spring-context里找不到类,我们重新运行一下这个模块的所有java下的test文件

其他的问题也是一样的处理方式,全部处理完

继续运行demo

好,编译成功了,可以写注释了

至此,我们的spring源码编译成功.下面我会继续更新spring相关的应用和源码博客,欢迎大家继续关注,可以的话随手点个赞吧,谢谢大家

1.编译spring源码的更多相关文章

  1. spring源码系列(一)sring源码编译 spring源码下载 spring源码阅读

    想对spring框架进行深入的学习一下,看看源代码,提升和沉淀下自己,工欲善其事必先利其器,还是先搭建环境吧. 环境搭建 sping源码之前是svn管理,现在已经迁移到了github中了,新版本基于g ...

  2. 编译Spring源码

    近期,学习Spring源码.会陆续记录这次学习历程. Spring源码下载,环境中需要准备好的东西,git,gradle,eclipse (需要自己安装好) 1.Git clone Spring源码: ...

  3. grable编译spring源码并导入eclipse

    1.下载安装gradle, spring 源码构建加入了gradle支持. gradle下载: http://www.gradle.org/downloads ,下载后设置环境变量: GRADLE_H ...

  4. 记一次Idea+Gradle编译Spring源码遇到的坑

    打算开始研究Spring源码,于是照着书上的指导从网上下载了Spring5.0.2版本和Gradle4.0(必须JDK1.8.60以上),本地编译的时候没有任何问题,就是导入Idea的时候一直报下面这 ...

  5. Gradle编译Spring源码

    使用工具:JDK1.8.0_11.Gradle4.9.idea2018.1.3 1. 配置Gradle Gradle下载地址:https://gradle.org/releases/ 在下载页找到自己 ...

  6. 修改和编译spring源码,构建jar(spring-context-4.0.2.RELEASE)

    上周在定位问题时,发现Spring容器实例化Bean的时候抛出异常,为了查看更详细的信息,决定修改spring-context-4.0.2.RELEASE.jar中的CommonAnnotationB ...

  7. 如何编译spring源码,并导入到eclipse中

    wsc@WSC-PC /d/wsc/study-spring-source$ git clone https://github.com/spring-projects/spring-framework ...

  8. Spring源码学习01:IntelliJ IDEA2019.3编译Spring5.3.x源码

    目录 Spring源码学习01:IntelliJ IDEA2019.3编译Spring5.3.x源码 前言 工欲善其事必先利其器.学习和深读Spring源码一个重要的前提:编译源码到我们的本地环境.这 ...

  9. Spring源码解析 | 第一篇 :IntelliJ IDEA2019.3编译Spring5.3.x源码

    前言 工欲善其事必先利其器.学习和深读Spring源码一个重要的前提:编译源码到我们的本地环境.这样方便我们在本地环境添加注释.断点追踪.查看类或接口的继承关系等等,更加高效的学习Spring源码.个 ...

随机推荐

  1. Tensorflow搭建CNN实现验证码识别

    完整代码:GitHub 我的简书:Awesome_Tang的简书 整个项目代码分为三部分: Generrate_Captcha: 生成验证码图片(训练集,验证集和测试集): 读取图片数据和标签(标签即 ...

  2. 程序员常用markdown语法记忆小结

    0.toc被中括号包围,实现自动提取标题生成目录 [TOC]   1.*的用法 * 一星:黑点 *二星:斜体* 三星:分割线 * * * **四星:粗体**   2.#的用法 # 1级标题 ## 2j ...

  3. Redis 命令执行过程(上)

    今天我们来了解一下 Redis 命令执行的过程.在之前的文章中<当 Redis 发生高延迟时,到底发生了什么>我们曾简单的描述了一条命令的执行过程,本篇文章展示深入说明一下,加深读者对 R ...

  4. JsonModel的使用

    本人最近在开发一款医疗类的APP 发现接口返回的数据很复杂 手动解析的话对新手来说就是一场灾难 在分解成所需要的model类型时工作量非常的大,于是从网上查阅相关资料,发现JsonModel这个第三方 ...

  5. dotnet core gbk 编码错误解决方案

    .Net Core GBK解码 1.添加引用 System.Text.Encoding.CodePages 2.注册   Encoding.RegisterProvider(CodePagesEnco ...

  6. B.Box

    题目:盒子 题目:排列p是一个整数序列 p = [p1, p2,...,pn],由n个唯一的正整数组成 唯一的线索是你需要打开上锁的盒子 你只知道前缀的最大数,q1, q2, ..., qn,保证qi ...

  7. java的传参究竟是按值传递的还是按引用传递的

    这里来弄清楚Java的传参究竟是按值传递的还是按引用传递的. 形参和实参 传参的概念里,有形参和实参的区分.形参是定义方法名和方法体的时候使用的参数,目的是用来接收调用该方法的时候传入的参数:实参是调 ...

  8. .net access config 相对路径

    <configuration> <connectionStrings> <add name="ConStr" connectionString=&qu ...

  9. Web基础了解版03-jQuery

    jQuery jQuery,顾名思义,也就是JavaScript和查询(Query)极大地简化了JavaScript开发人员遍历HTML文档.操作DOM.处理事件.执行动画和开发Ajax. jQuer ...

  10. SOCKET CAN的理解

    转载请注明出处:http://blog.csdn.net/Righthek 谢谢! CAN总线原理 由于Socket CAN涉及到CAN总线协议.套接字.Linux网络设备驱动等.因此,为了能够全面地 ...