spring体系结构(基于4.X)
前言
spring加载方式:
- 配置类xml
- spring2.5注解 annotation-based
- spring3.0支持java配置类的方式 @Bean @Import @Configuration
spring编译流程
- 下载spring源码:https://github.com/spring-projects/spring-framework
- 安装源码gradle版本(也可以不安装),建议使用[gradleWraper中的gradle
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
- 修改build.gradle,设置阿里云镜像
repositories {
maven{ url 'https://maven.aliyun.com/nexus/content/groups/public/' }
maven{ url 'https://maven.aliyun.com/nexus/content/repositories/jcenter' }
mavenCentral()
maven { url "https://repo.spring.io/libs-spring-framework-build" }
}
- 编译源码:compile TestJava模块
./gradlew :spring-oxm:compileTestJava
- 设置gradle
IOC加载整体流程
Inversion of Control(IoC) :用来解决层层、类类之间的耦合问题
BeanFactory和ApplicationContext
Spring用于所有常见目的的核心容器的主要入口点:加载配置文件,触发类路径扫描,以编程方式注册bean定义和带注解的类,以及(从5.0开始)注册功能bean定义。对于注解处理和AOP代理, BeanPostProcessor扩展点也是必不可少的
由图所见:ApplicationContext包括BeanFactory的所有功能,BeanFactory相比更值得推荐,除了一些特定的场景,例如在资源受限的设备上运行的内嵌的应用。