gradle安装教程

本地必须有JAVA环境

[root@localhost ~]# java -version
java version "1.8.0_221"
Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)

执行命令

brew install gradle

搭建Spring源码

下载Spring

git clone git@github.com:spring-projects/spring-framework.git

阅读文档

import-into-idea.md

预编译Spring

./gradlew cleanIdea :spring-oxm:compileTestJava

排除模块

spring-aspects  这个不排除Idea报错

启动Spring

配置文件

package com.pv3.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan("com.pv3")
public class AnnotationConfig {
}

编写Bean

package com.pv3.utils;

import org.springframework.stereotype.Component;

@Component
public class TestUtil {
	public void hello(){
    	System.out.println("hello world");
	}
}

使用

package com.pv3;

import com.pv3.config.AnnotationConfig;
import com.pv3.utils.TestUtil;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Test {
  public static void main(String[] args) {
	  //启动Spring
	  AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(AnnotationConfig.class);
	  TestUtil bean = annotationConfigApplicationContext.getBean(TestUtil.class);
	  bean.hello();

  }
}