spring源码

搭建环境

生成的源码

本次使用的源码Spring4.3.x,JDK8,gradle4.10.2,idea2018.2.5

Spring源码使用的是Gradle 进行构建的,所以需要下载 Gradle 以及搭建 java开发环境

Java环境使用的是 JDK1.8
JDK版本.png

Gradle版本4.10.2 Gradle下载

 spring-framework-4.3.x.zip 包:查看build.gradle文件 查询gradlew 有推荐匹配的gradle版本号

Spring源码下载地址:Spring源码下载

开始编译

Spring官方给出的步骤

  1. 进入Spring源码目录cd spring-framework-4.3.x
  2. 执行脚本:gradlew.bat cleanIdea :spring-oxm:compileTestJava

导入idea

File-->new-->Project from Existing Sources... 选中解压的目录(spring-framework-4.3.x)

 如果build报错,一般都是引用的jar无法下载到

修改配置build.gradle 添加maven仓库

注意:有2个地方需要添加,我这边应该是加多了,但是以防万一都加上了

可以参考:阿里仓库服务

buildscript {
	repositories {
		maven { url "https://maven.aliyun.com/repository/public" }
		gradlePluginPortal()
		maven { url "https://repo.spring.io/plugins-release" }
	}
repositories {
		maven{ url 'https://maven.aliyun.com/repository/public'}
		maven{ url 'https://maven.aliyun.com/repository/apache-snapshots'}
		maven{ url 'https://maven.aliyun.com/repository/central'}
		maven{ url 'https://maven.aliyun.com/repository/spring-plugin'}
		maven{ url 'https://maven.aliyun.com/nexus/content/groups/public'}
		maven{ url 'https://maven.aliyun.com/nexus/content/repositories/jcenter'}
		mavenCentral()
		maven { url "https://repo.spring.io/libs-spring-framework-build" }
	}

然后基本上加载就没有问题了

代码build

build会报各种问题,首先build去除test模块的代码,用  build -x test 执行

创建module:test-spring

package com.ywm;

/**
 * @Description
 * @Author YuanWeiMin
 * @Date 2022-05-24 17:57
 */
public class TestBean {
    public TestBean() {
        System.out.println("init.......");
    }

    public void test() {
        System.out.println("test.......");
    }

}
package com.ywm;

import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @Description
 * @Author YuanWeiMin
 * @Date 2022-05-24 17:56
 */
public class TestSpring {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext ctx =
                new ClassPathXmlApplicationContext("beans.xml");
        System.out.println(ctx.getId());
        TestBean tb = ctx.getBean(TestBean.class);
        tb.test();
    }

}
<?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 class="com.ywm.TestBean"/>

</beans>

启动报错:ClassPathXmlApplicationContext 无法加载

解决办法:子模块的build.gradle配置添加

 如果spring-context:main里面无法加载aop文件

解决办法:模块的build.gradle配置添加

 遇到的问题到此结束

启动test

 遇到特殊情况,这个里面的main方法的jdk默认选中6,需要特殊注意一下,应该是我电脑同时安装了jdk6和jdk8

记录:

零零总总搞了好几天,主要是各种编译问题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值