【Spring源码解析】-1.源码编译

下载源码

  • 下载地址:spring.io->projects->Spring Framework->github spring源码托管
  • 选择tag:找到最新release源码
  • 下载spring 压缩包,并解压

编译源码

  • 进入spring解压包

  • 修改build.gradle文件,将仓库地址改为阿里云

  • gradle依赖仓库

    buildscript {
    	repositories {
    		maven { url 'http://maven.aliyun.com/nexus/content/groups/public/'}
    		maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
    	}
    }
    
  • 项目依赖仓库

    configure(allprojects){
    	repositories {
    		maven { url 'http://maven.aliyun.com/nexus/content/groups/public/'}
    		maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
    		mavenCentral()
    		maven { url "https://repo.spring.io/libs-spring-framework-build" }
    	}
    }
    
  • 编译 spring-oxm

    ./gradlew :spring-oxm:compileTestJava
    
  • 将spring源码导入idea

  • 排除spring-aspects

    • 选择spring-aspects模块
    • 右键load/unload-modules
    • 选择spring-aspects,执行unload

测试源码

  • 新建module,spring-demo
  • 引入spring-context依赖
    dependencies {
    	//编译,引入项目project为当前项目模块
        compile(project(":spring-context"))
        }
    
  • 项目中书写service,并在启动类中引入service,通过context上下文成功获取service的bean,表示源码编译成功

你可能感兴趣的:(spring源码解析,spring,java,gradle)