使用idea构建Spring源码5.2.x

首先去github上找到这个资源
https://github.com/spring-projects/spring-framework

git clone -b 5.2.x https://github.com/spring-projects/spring-framework.git

等待下载完毕 然后用idea导入这个下载的项目即可

在这里插入图片描述
这里选择的是gradle编译的!!!
源码是用gradle编译的不是maven
导入项目之后就等着下载依赖就好了
可能会出现缺少AspectJ 在idea中下载插件即可
在这里插入图片描述
依赖下载的特别慢 请耐心的等待
build successful之后就开始搭建测试的案例
新建一个module spring-debug
在这里插入图片描述
然后修改build.gradle

plugins {
    id 'java'
}

group 'org.springframework'
version '5.2.18.BUILD-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
    implementation(project(":spring-context"))
    compile 'org.aspectj:aspectjrt:1.9.7'
    compile(project(":spring-beans"))
    compile(project(":spring-core"))
    compile(project(":spring-context"))
    compile(project(":spring-webmvc"))
    compile(project(":spring-jdbc"))
    compile(project(":spring-orm"))
    compile(project(":spring-tx"))
    compile(project(":spring-web"))
    compile(project(":spring-context-indexer"))
    compile(project(":spring-context-support"))
    compile(project(":spring-expression"))
    compile(project(":spring-instrument"))
    compile(project(":spring-jcl"))
    compile(project(":spring-jms"))
    compile(project(":spring-messaging"))
    compile(project(":spring-oxm"))
    compile(project(":spring-test"))
    compile(project(":spring-webflux"))
    compile(project(":spring-websocket"))
//    compile(project(":spring-aspects"))
//    compile('org.springframework:spring-aspectj:5.2.9')
    compile("org.aspectj:aspectjweaver:1.9.6")
    compile(project(":spring-aop"))
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile("com.alibaba:druid:1.2.4")
    compile("mysql:mysql-connector-java:5.1.48")
}

test {
    useJUnitPlatform()
}

这里不修改的话 很多地方都不能够引用
创建一个test

 public class Test {

    public static void main(String[] args) {
 ApplicationContext ac = new ClassPathXmlApplicationContext("person.xml");
 	Person bean = ac.getBean(Person.class);
	System.out.println(bean);
	 }
 }

创建一个person类

public class Person  {

   
    private Integer id;
    private String name;

    public Person() {
        System.out.println("构造方法");
    }

    public Person(Integer id, String name) {
        this.id = id;
        this.name = name;
    }

    

    public Person(String name,Integer id) {
        this.id = id;
        this.name = name;
    }


    public Person(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Person{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }
}

创建一个person.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"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">



    <bean id="person" class="com.yzy.Person" scope="prototype">
        <property name="id" value="1"></property>
        <property name="name" value="zhangsan"></property>
        <constructor-arg name="id" value="1"></constructor-arg>
        <constructor-arg name="name" value="lisi"></constructor-arg>
    </bean>

</beans>

最后运行效果
在这里插入图片描述
ok 大公告成

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值