环境:`在这里插入代码片
allprojects { repositories { maven { url 'file:///D:/software/repository'} // 本地仓库地址,如果没有依次向下寻找 maven { url "https://maven.aliyun.com/repository/public" } mavenLocal() mavenCentral() } buildscript { repositories { maven { url 'https://maven.aliyun.com/repository/public' } mavenLocal() mavenCentral() } } }
- 先用gradle 编译整个spring-framework
配置如下
maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' } maven { url 'https://maven.aliyun.com/nexus/content/repositories/jcenter'}
implementation(project(':spring-context')) implementation 'org.projectlombok:lombok:1.18.22'
- 定义一个类
package com.macc; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import org.springframework.stereotype.Component; /** * @author mcc * @title: Dog */ @AllArgsConstructor @NoArgsConstructor @Data @Component public class Dog { private Integer age; public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } @Override public String toString() { return "Dog{" + "age=" + age + '}'; } }
- main方法运行
package com.macc; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; public class Main { public static void main(String[] args) { System.out.println("Hello world!"); ApplicationContext applicationContext = new AnnotationConfigApplicationContext("com.macc"); System.out.println(applicationContext.getBean(Dog.class)); } }
运行成功!!!
可以在源码里面加上自己的理解
还没有评论,来说两句吧...