spring5.3.x源码路径下载:
https://gitee.com/xuchang614/spring-framework.git
gradle对应版本为7.5.1:
https://services.gradle.org/distributions/gradle-7.5.1-bin.zip
配置类:
@ComponentScan("com.xc")
@Configuration
public class Config {
@Bean()
public Book book(){
return new Book();
}
}
启动类:
public class Client {
public static void main(String[] args) {
//创建注解容器,入参为配置类
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
//获取某个bean
Book book = context.getBean(Book.class);
System.out.println(book);
//关闭容器
context.close();
}
}
源码目录展示及案例demo: