01 源码环境构建

2020-09-21  本文已影响0人  格林哈

1, 配置环境

git clone -b 5.0.x https://gitee.com/mirrors/Spring-Framework.git
GRADLE_HOME   D:\softwareStudy\gradle-4.7
path 加上 %GRADLE_HOME%\bin
GRADLE_USER_HOME    E:\softwareInfo\mavnRepo

# 用户目录添加 .gradle 文件添加 init.gradle 文件

allprojects{
    repositories {
        def REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public/'
        all { ArtifactRepository repo ->
            if(repo instanceof MavenArtifactRepository){
                def url = repo.url.toString()
                if (url.startsWith('https://repo1.maven.org/maven2') || url.startsWith('https://jcenter.bintray.com/')) {
                    project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
                    remove repo
                }
            }
        }
        maven {
            url REPOSITORY_URL
        }
    }
}


// 加入依赖 build.gradle 
 compile(project(":spring-beans"))
    compile(project(":spring-core"))
    optional(project(":spring-aop"))
    optional(project(":spring-context"))  
//写一个测试类
@Component("ibean")
public class IBean {
    private String name = "mg";
    private String id = "1";

    public String getName() {
        return name;
    }

}


public class IBeanTest {
    @Test
    public void getBean() {
        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext();
        annotationConfigApplicationContext.scan("com.mg.bean");
        annotationConfigApplicationContext.refresh();
        IBean ibean = (IBean) annotationConfigApplicationContext.getBean("ibean");
        System.out.println(ibean.getName());

    }
}
上一篇 下一篇

猜你喜欢

热点阅读