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

下载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. c# 窗体开发4 数据库访问技术

    ADO.NET的名称起源于ADO(ACTIVEX DATA OBJECTS) USING SYSTEM; USING SYSTEM.COLLECTIONS.GENERIC; USING SYSTEM. ...

  2. 在开发Thinkphp5.0智慧软文个人微信个人支付宝企业支付宝接口时遇到的坑

    在开发Thinkphp5.0智慧软文个人微信个人支付宝企业支付宝接口时遇到回调后提示成功但是不能自动充值的情况,现在记录一下: 两种情况 1.个人支付宝  个人微信遇到的情况 因为个人支付宝 个人微信 ...

  3. mysql那些事(5)建表存储引擎的选择

    在mysql见表的时候,会遇到选择存储引擎:MyISAM和InnoDB.究竟用哪种存储引擎好呢? 1.MyISAM:表锁:支持全文索引:读并发性能较好. 2.InnoDB:行锁:支持事务,支持外键:写 ...

  4. phpStorm自动生成___jb_tmp___文件

    把这个去掉就可以了

  5. 输入URL按下enter键后发生的事

    输入URL按下enter键后浏览器和服务器各自发生的事. 浏览器 1.用户在浏览器中输入URL地址 2.浏览器解析用户输入的URL地址=>域名+端口 3.浏览器检查本地缓存中是否存在这个域名=& ...

  6. elementUI最新版的el-select使用filterable无效无法匹配正确搜索结果的Bug解决办法

    Bug描述: 今天做开发时遇到一个elementUI存在的bug. 当el-select使用filterable功能搜索时,如果你恰巧使用的是微软拼音输入法,那么你有可能会遇到搜索结果和输入的值不匹配 ...

  7. shell 脚本运行 hive sql

    #!/b START=$(date +%s); datebegin=`date -d "$1" "+%Y%m%d"` dateend=`date -d &quo ...

  8. react-native scrollview触摸滚动事件

    目录 1.几个已知的滑动或者滑动开始结束的方法: 2.还有其他的一些事件如下 3.下面就这些方法的顺序做个简单的介绍: 4.android上的时间分为两种,一个是滑动一次,一个是连续滑动两次甚至多次, ...

  9. 在Linux中配置jdk,Tomcat,MySQL

    解压缩: tar 命令 : 使用方式 tar [参数] source [target] source - 压缩文件 target - 解压缩后的目标位置, 默认解压到当前目录 常用写法 : 解压缩 : ...

  10. CoderFocers-620C

    There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the rig ...