1.编译spring源码
本文是作者原创,版权归作者所有.若要转载,请注明出处
下载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源码的更多相关文章
- spring源码系列(一)sring源码编译 spring源码下载 spring源码阅读
想对spring框架进行深入的学习一下,看看源代码,提升和沉淀下自己,工欲善其事必先利其器,还是先搭建环境吧. 环境搭建 sping源码之前是svn管理,现在已经迁移到了github中了,新版本基于g ...
- 编译Spring源码
近期,学习Spring源码.会陆续记录这次学习历程. Spring源码下载,环境中需要准备好的东西,git,gradle,eclipse (需要自己安装好) 1.Git clone Spring源码: ...
- grable编译spring源码并导入eclipse
1.下载安装gradle, spring 源码构建加入了gradle支持. gradle下载: http://www.gradle.org/downloads ,下载后设置环境变量: GRADLE_H ...
- 记一次Idea+Gradle编译Spring源码遇到的坑
打算开始研究Spring源码,于是照着书上的指导从网上下载了Spring5.0.2版本和Gradle4.0(必须JDK1.8.60以上),本地编译的时候没有任何问题,就是导入Idea的时候一直报下面这 ...
- Gradle编译Spring源码
使用工具:JDK1.8.0_11.Gradle4.9.idea2018.1.3 1. 配置Gradle Gradle下载地址:https://gradle.org/releases/ 在下载页找到自己 ...
- 修改和编译spring源码,构建jar(spring-context-4.0.2.RELEASE)
上周在定位问题时,发现Spring容器实例化Bean的时候抛出异常,为了查看更详细的信息,决定修改spring-context-4.0.2.RELEASE.jar中的CommonAnnotationB ...
- 如何编译spring源码,并导入到eclipse中
wsc@WSC-PC /d/wsc/study-spring-source$ git clone https://github.com/spring-projects/spring-framework ...
- Spring源码学习01:IntelliJ IDEA2019.3编译Spring5.3.x源码
目录 Spring源码学习01:IntelliJ IDEA2019.3编译Spring5.3.x源码 前言 工欲善其事必先利其器.学习和深读Spring源码一个重要的前提:编译源码到我们的本地环境.这 ...
- Spring源码解析 | 第一篇 :IntelliJ IDEA2019.3编译Spring5.3.x源码
前言 工欲善其事必先利其器.学习和深读Spring源码一个重要的前提:编译源码到我们的本地环境.这样方便我们在本地环境添加注释.断点追踪.查看类或接口的继承关系等等,更加高效的学习Spring源码.个 ...
随机推荐
- C# MVC 过滤器
APS.NET MVC中(以下简称“MVC”)的每一个请求,都会分配给相应的控制器和对应的行为方法去处理,而在这些处理的前前后后如果想再加一些额外的逻辑处理.这时候就用到了过滤器. MVC支持的过滤器 ...
- Netty源码分析之ChannelPipeline(二)—ChannelHandler的添加与删除
上篇文章中,我们对Netty中ChannelPipeline的构造与初始化进行了分析与总结,本篇文章我们将对ChannelHandler的添加与删除操作进行具体的的代码分析: 一.ChannelHan ...
- 写一个umi插件 自动生成代码 解放cv的双手
引言 最近在写一个中台项目,使用的react的umi框架. 各种增删改查.基本是列表页 新建页 详情页这种页面 为了避免不必要的简单重复(主要是想偷懒) 于是想去实现自己的一个代码生成器 探索 首先, ...
- 用C#写小工具:将圆柱面贴图映射到半球贴图
最近在写GBA的程序.GBA运行的是C的裸机代码,而中途使用的很多小工具则用C#写的,例如:图片转换到.h头文件,制作三角函数表,还有像这次介绍的将圆柱面贴图映射到半球贴图的小工具.这样的小功能,用C ...
- 【强化学习】DQN 算法改进
DQN 算法改进 (一)Dueling DQN Dueling DQN 是一种基于 DQN 的改进算法.主要突破点:利用模型结构将值函数表示成更加细致的形式,这使得模型能够拥有更好的表现.下面给出公式 ...
- HDU-1754 A - I Hate It
很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问.当然,老师有 ...
- python学习笔记—DataFrame和Series的排序
更多大数据分析.建模等内容请关注公众号<bigdatamodeling> ################################### 排序 ################## ...
- Appium之环境搭建
Appium:是开源.跨平台.多语言支持的移动应用自动化工具 测试对象主要有:① 原生app ② 混合app(h5 + web前端基础) ③ 移动web app 测试对象APPy运行平台: ① io ...
- 谈一谈AOP面向切面编程
AOP是什么 : AOP面向切面编程他是一种编程思想,是指在程序运行期间,将某段代码动态的切入到指定方法的指定位置,将这种编程方式称为面向切面编程 AOP使用场景 : 日志 事务 使用AOP的好处是: ...
- 为什么有ASP.NET
最近读了一些文章,总结一下: 在1999年,当时微软的windows系统运行的所有的应用程序都是有组件对象模型为根本基础开发的,用VB来处理数据访问和复杂的用户界面,缺点是不能使用函数指针,因为当时的 ...