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

下载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. JavaEE基础(01):Servlet实现方式,生命周期执行过程

    本文源码:GitHub·点这里 || GitEE·点这里 一.Servlet简介 Java编写的服务器端程序,具有独立于平台和协议的特性,主要功能在于交互式地浏览和生成数据,生成动态Web内容.使用S ...

  2. C# 中的委托和事件(一)

    引言 委 托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易.它们就像是一道槛儿,过了这个槛的人,觉得真 是太容易了,而没有 ...

  3. 你的SpringBoot应用真的部署更新成功了吗

    前提 当我们在生产环境部署了SpringBoot应用的时候,虽然可以通过Jenkins的构建状态和Linux的ps命令去感知应用是否在新的一次发布中部署和启动成功,但是这种监控手段是运维层面的.那么, ...

  4. react文本溢出hover气泡显示全部文本——JS判断文本溢出

    需求: 在文本溢出的时候,显示气泡 JS相关知识 // target js元素 const containerLength = target.width; //当前容器的宽度 const textLe ...

  5. CSS_实现京东购物车静态页面

    主页面分配: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> < ...

  6. 学习go语言第二天-变量、常量

    编写测试程序 源码文件以_test结尾;例如:xxx_test.go 测试方法名以Test开头;例如:func TestXXXXX(t *testing.T){} 实现斐波那且数列 package f ...

  7. POJ3261 Milks patterns(后缀数组)

    Farmer John has noticed that the quality of milk given by his cows varies from day to day. On furthe ...

  8. HDU 1520 Anniversity party

    There is going to be a party to celebrate the 80-th Anniversary of the Ural State University. The Un ...

  9. 2018HDU多校训练一 D Distinct Values

    hiaki has an array of nn positive integers. You are told some facts about the array: for every two e ...

  10. 【CSS】398- 原生JS实现DOM爆炸效果

    爆炸动效分享 前言 此次分享是一次自我组件开发的总结,还是有很多不足之处,望各位大大多提宝贵意见,互相学习交流. 分享内容介绍 通过原生js代码,实现粒子爆炸效果组件 组件开发过程中,使用到了公司内部 ...