编译spring源码1

8 篇文章 0 订阅
5 篇文章 0 订阅

编译spring源码

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源码

img

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

img

3.选择该项目路径

img

4.选择gradle导入

img

5.等待它自己构建

img

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

img

7.如图,设置gradle配置

img

8.先编译spring-core模块

img

9.编译成功

img

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

img

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

img

img

11.忽略spring-aspects模块

img

12.编译整个spring模块

img

img

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

img

img

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

img

img

img

img

点击,右上角的ok

img

加上以下代码

[复制代码](javascript:void(0)😉

//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'

[复制代码](javascript:void(0)😉

最后build.gradle文件内容如下

[复制代码](javascript:void(0)😉

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'
}

[复制代码](javascript:void(0)😉

15.编写demo

[复制代码](javascript:void(0)😉

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();
        

    }

}

[复制代码](javascript:void(0)😉

xml配置

[复制代码](javascript:void(0)😉

<?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>

[复制代码](javascript:void(0)😉

16.运行,报错

img

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

img

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

继续运行demo

img

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

img

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

最后:

我想,可能还有很多人在今年刚过去的金三银四春招中保持着观望的形势,害怕自己的能力不够,或者是安于现状,觉得目前拿着几千的月薪觉得能够接受,那么你就要注意了,这是非常危险的!

我们身为技术人员,最怕的就是安于现状,一直在原地踏步,那么你可能在30岁就会迎来自己的职业危机,因为你工作这么久提升的只有自己的年龄,技术还是万年不变!

如果你想在未来能够自我突破,圆梦大厂,那或许以上这份Java学习资料,你需要阅读阅读,希望能够对你的职业发展有所帮助。

获取方式: 只需你**点赞+关注**后,进[Java架构资源交流群] ,找管理员获取哦-!

千的月薪觉得能够接受,那么你就要注意了,这是非常危险的!

我们身为技术人员,最怕的就是安于现状,一直在原地踏步,那么你可能在30岁就会迎来自己的职业危机,因为你工作这么久提升的只有自己的年龄,技术还是万年不变!

如果你想在未来能够自我突破,圆梦大厂,那或许以上这份Java学习资料,你需要阅读阅读,希望能够对你的职业发展有所帮助。

获取方式: 只需你**点赞+关注**后,进[Java架构资源交流群] ,找管理员获取哦-!

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值