编译spring源码

环境:

  • jdk1.8
  • spring 5.20
  • IDEA 2019

下载

  1. 进入https://spring.io/

  2. 选择spring framework,进入github
    在这里插入图片描述
    在这里插入图片描述

  3. 选择稳定版下载
    在这里插入图片描述

编译

  1. 参考官方教程:https://github.com/spring-projects/spring-framework/blob/main/import-into-idea.md
    github界面选择:
    在这里插入图片描述
    在wiki的界面翻到最后:
    在这里插入图片描述

  2. 按照step里面的步骤进行
    使用gradlew编译,添加下述语句
    在这里插入图片描述
    在这里插入图片描述

    # 修改的第一部分
    repositories {
            maven{ url 'https://maven.aliyun.com/nexus/content/groups/public/' }
            maven{ url 'https://maven.aliyun.com/nexus/content/repositories/jcenter'}
    }
    
    
    # 修改的第而部分
    maven{ url 'https://maven.aliyun.com/nexus/content/groups/public/'}
    maven{ url 'https://maven.aliyun.com/nexus/content/repositories/jcenter'}
    
  3. 保存后,在spring框架目录下打开cmd执行./gradlew :spring-oxm:compileTestJava(如果是windows的话,执行.\gradlew :spring-oxm:compileTestJavagradlew :spring-oxm:compileTestJava

  4. IDEA import项目

    在这里插入图片描述
    在这里插入图片描述

  5. 把spring-aspect给upload出去,然后重新编译
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

测试使用

  1. 新建module,注意选择gradle创建(maven和gradle共存会有问题)
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

  2. 新建package和class
    在这里插入图片描述
    在这里插入图片描述
    最终的文件结构如图:
    在这里插入图片描述

  3. Service实现
    接口:

    package com.mytest.service;
    
    public interface WelcomeService {
    	String sayHello(String name);
    }
    

    实现类:

    package com.mytest.service.impl;
    
    import com.mytest.service.WelcomeService;
    
    public class WelcomeServiceImpl implements WelcomeService {
    	@Override
    	public String sayHello(String name) {
    		System.out.println("欢迎");
    		System.out.println(name);
    		return "success";
    	}
    }
    
  4. resource里的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
           http://www.springframework.org/schema/beans/spring-beans.xsd">
    	<bean id="welcomeService" class="com.mytest.service.impl.WelcomeServiceImpl"/>
    </beans>
    
  5. gradle

    plugins {
        id 'java'
    }
    
    group 'org.springframework'
    version '5.2.0.RELEASE'
    
    sourceCompatibility = 1.8
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        compile(project(":spring-context"))
        testCompile group: 'junit', name: 'junit', version: '4.12'
    }
    

    新加了语句:compile(project(":spring-context")),加完后在IDEA右下角,自动导入
    在这里插入图片描述

  6. 入口函数Entrance

    package com.mytest;
    
    import com.mytest.service.WelcomeService;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.FileSystemXmlApplicationContext;
    
    public class Entrance {
    	public static void main(String[] args) {
    		String xmlPath = "D:\\spring-framework-5.2.0.RELEASE\\springdemo\\src\\main\\resources\\spring\\spring-config.xml";
    		ApplicationContext applicationContext = new FileSystemXmlApplicationContext(xmlPath);
    		WelcomeService welcomeService = (WelcomeService) applicationContext.getBean("welcomeService");
    		welcomeService.sayHello("啦啦啦,a test");
    	}
    }
    

然后点击运行就可以了。


报错:

Error:(347, 51) java: 找不到符号
  符号:   变量 CoroutinesUtils
  位置: 类 org.springframework.core.ReactiveAdapterRegistry.CoroutinesRegistrar

在这里插入图片描述

解决方法:
点击File -> Project Structure -> Libraries -> + -> Java,然后选择spring-framework/spring-core/kotlin-coroutines/build/libs/kotlin-coroutines-5.2.4.BUILD-SNAPSHOT.jar,在弹出的对话框中选择spring-core.main,在重新build项目即可。

参考:
https://blog.csdn.net/gooaaee/article/details/104437902

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值