目录
1. IoC容器
1.1. Spring IoC 容器和 Bean 简介
1.2. 容器概述
1.2.1. 配置元数据
1.2.2. 实例化容器
1.2.3. 使用容器
1.3. Bean 概述
1.3.1. 命名 Bean
1.3.2. 实例化 Bean
1.4. 依赖关系
1.4.1. 依赖注入
- 基于构造函数的依赖注入
- 基于 Setter 的依赖注入
- 依赖解析过程
- 依赖注入的示例
1.4.2. 依赖关系和配置详细信息
- 直接值(原语、字符串等)
- 对其他 Bean(合作者)的引用
- 内部的Bean
- 集合
- Null 和空字符串值
- 带有 p 命名空间的 XML 快捷方式
- 带有 c 命名空间的 XML 快捷方式
- 复合属性名称
1.5. Bean 范围
1.5.1. 单例范围
1.5.2. 原型范围
1.5.3. 具有原型 bean 依赖性的单例 Bean
1.5.4. 请求、会话、应用程序和 WebSocket 范围
- 初始网络配置
- request范围
- Session范围
- application 范围
- 作用域 Bean 作为依赖项
1.5.5. 定制范围
- 创建自定义范围
- 使用自定义范围
1.6. 定制 Bean 的性质
1.6.1. 生命周期回调
- 初始化回调
- 销毁回调
- 默认初始化和销毁方法
- 结合生命周期机制
- 启动和关闭回调
- 在非 Web 应用程序中正常关闭 Spring IoC 容器
1.6.2. ApplicationContextAware 和 BeanNameAware
1.6.3. 其他感知接口
1.7. Bean定义继承
1.8. 容器扩展端点
1.8.1. 使用 BeanPostProcessor 自定义 Bean
- 示例:Hello World,BeanPostProcessor 风格
- 示例:AutowiredAnnotationBeanPostProcessor
1.8.2. 使用 BeanFactoryPostProcessor 自定义配置元数据
- 示例:类名替换 PropertySourcesPlaceholderConfigurer
- 示例:PropertyOverrideConfigurer
1.8.3. 使用 FactoryBean 自定义实例化逻辑
1.9. 基于注解的容器配置
1.9.1. @必需的
1.9.2. 使用@Autowired
1.9.3. 使用 @Primary 微调基于注释的自动装配
1.9.4. 使用限定符微调基于注释的自动装配
1.9.5. 使用泛型作为自动装配限定符
1.9.6. 使用自定义AutowireConfigurer
1.9.7. 使用@Resource注入
1.9.8. 使用@Value
1.9.9. 使用@PostConstruct和@PreDestroy
1.10. 类路径扫描和托管组件
1.10.1. @Component 和进一步的刻板印象注释
1.10.2. 使用元注释和组合注释
1.10.3. 自动检测类并注册 Bean 定义
1.10.4. 使用过滤器自定义扫描
1.10.5. 在组件内定义 Bean 元数据
1.10.6. 命名自动检测到的组件
1.10.7. 为自动检测的组件提供范围
1.10.8. 提供带有注释的限定符元数据
1.10.9. 生成候选组件的索引
1.11. 使用 JSR 330 标准注释
1.11.1. 使用@Inject和@Named进行依赖注入
1.11.2. @Named 和 @ManagedBean:@Component 注解的标准等效项
1.11.3. JSR-330 标准注释的限制
1.12. 基于Java的容器配置
1.12.1. 基本概念:@Bean和@Configuration
1.12.2. 使用AnnotationConfigApplicationContext实例化Spring容器
- 施工简单
- 使用 register(Class<?>…) 以编程方式构建容器
- 使用 scan(String…) 启用组件扫描
- 使用 AnnotationConfigWebApplicationContext 支持 Web 应用程序
1.12.3. 使用@Bean注解
- 声明一个 Bean
- Bean 依赖关系
- 接收生命周期回调
- 指定 Bean 范围
- 自定义 Bean 命名
- Bean 别名
- Bean 描述
1.12.4. 使用@Configuration注解
- 注入 bean 间依赖关系
- 查找方法注入
- 有关基于 Java 的配置如何在内部工作的更多信息
1.12.5. 组合基于 Java 的配置
- 使用@Import注释
- 有条件地包含 @Configuration 类或 @Bean 方法
- 结合 Java 和 XML 配置
1.13. 环境抽象
1.13.1. Bean 定义配置文件
- 使用@Profile
- XML Bean 定义配置文件
- 激活个人资料
- 默认配置文件
1.13.2. 属性源抽象
1.13.3. 使用@PropertySource
1.13.4. 语句中的占位符解析
1.14. 注册 LoadTimeWeaver
1.15. ApplicationContext 的附加功能
1.15.1. 使用 MessageSource 进行国际化
1.15.2. 标准和自定义事件
- 基于注释的事件监听器
- 异步监听器
- 排序监听器
- 通用事件
1.15.3. 便捷获取底层资源
1.15.4. Web 应用程序的便捷 ApplicationContext 实例化
1.15.5. 将 Spring ApplicationContext 部署为 Java EE RAR 文件
1.16. Bean工厂
1.16.1. BeanFactory 还是 ApplicationContext?
英文对照
-
The IoC Container
1.1. Introduction to the Spring IoC Container and Beans -
- Container Overview
1.2.1. Configuration Metadata
1.2.2. Instantiating a Container
1.2.3. Using the Container
- Container Overview
-
- Bean Overview
1.3.1. Naming Beans
1.3.2. Instantiating Beans
- Bean Overview
-
- Dependencies
1.4.1. Dependency Injection
Constructor-based Dependency Injection
Setter-based Dependency Injection
Dependency Resolution Process
Examples of Dependency Injection
1.4.2. Dependencies and Configuration in Detail
Straight Values (Primitives, Strings, and so on)
References to Other Beans (Collaborators)
Inner Beans
Collections
Null and Empty String Values
XML Shortcut with the p-namespace
XML Shortcut with the c-namespace
Compound Property Names
- Dependencies
-
- Bean Scopes
1.5.1. The Singleton Scope
1.5.2. The Prototype Scope
1.5.3. Singleton Beans with Prototype-bean Dependencies
1.5.4. Request, Session, Application, and WebSocket Scopes
Initial Web Configuration
Request scope
Session Scope
Application Scope
Scoped Beans as Dependencies
1.5.5. Custom Scopes
Creating a Custom Scope
Using a Custom Scope
- Bean Scopes
-
- Customizing the Nature of a Bean
1.6.1. Lifecycle Callbacks
Initialization Callbacks
Destruction Callbacks
Default Initialization and Destroy Methods
Combining Lifecycle Mechanisms
Startup and Shutdown Callbacks
Shutting Down the Spring IoC Container Gracefully in Non-Web Applications
1.6.2. ApplicationContextAware and BeanNameAware
1.6.3. Other Aware Interfaces
- Customizing the Nature of a Bean
-
- Bean Definition Inheritance
-
- Container Extension Points
1.8.1. Customizing Beans by Using a BeanPostProcessor
Example: Hello World, BeanPostProcessor-style
Example: The AutowiredAnnotationBeanPostProcessor
1.8.2. Customizing Configuration Metadata with a BeanFactoryPostProcessor
Example: The Class Name Substitution PropertySourcesPlaceholderConfigurer
Example: The PropertyOverrideConfigurer
1.8.3. Customizing Instantiation Logic with a FactoryBean
- Container Extension Points
-
- Annotation-based Container Configuration
1.9.1. @Required
1.9.2. Using @Autowired
1.9.3. Fine-tuning Annotation-based Autowiring with @Primary
1.9.4. Fine-tuning Annotation-based Autowiring with Qualifiers
1.9.5. Using Generics as Autowiring Qualifiers
1.9.6. Using CustomAutowireConfigurer
1.9.7. Injection with @Resource
1.9.8. Using @Value
1.9.9. Using @PostConstruct and @PreDestroy
- Annotation-based Container Configuration
-
- Classpath Scanning and Managed Components
1.10.1. @Component and Further Stereotype Annotations
1.10.2. Using Meta-annotations and Composed Annotations
1.10.3. Automatically Detecting Classes and Registering Bean Definitions
1.10.4. Using Filters to Customize Scanning
1.10.5. Defining Bean Metadata within Components
1.10.6. Naming Autodetected Components
1.10.7. Providing a Scope for Autodetected Components
1.10.8. Providing Qualifier Metadata with Annotations
1.10.9. Generating an Index of Candidate Components
- Classpath Scanning and Managed Components
-
- Using JSR 330 Standard Annotations
1.11.1. Dependency Injection with @Inject and @Named
1.11.2. @Named and @ManagedBean: Standard Equivalents to the @Component Annotation
1.11.3. Limitations of JSR-330 Standard Annotations
- Using JSR 330 Standard Annotations
-
- Java-based Container Configuration
1.12.1. Basic Concepts: @Bean and @Configuration
1.12.2. Instantiating the Spring Container by Using AnnotationConfigApplicationContext
Simple Construction
Building the Container Programmatically by Using register(Class<?>…)
Enabling Component Scanning with scan(String…)
Support for Web Applications with AnnotationConfigWebApplicationContext
1.12.3. Using the @Bean Annotation
Declaring a Bean
Bean Dependencies
Receiving Lifecycle Callbacks
Specifying Bean Scope
Customizing Bean Naming
Bean Aliasing
Bean Description
1.12.4. Using the @Configuration annotation
Injecting Inter-bean Dependencies
Lookup Method Injection
Further Information About How Java-based Configuration Works Internally
1.12.5. Composing Java-based Configurations
Using the @Import Annotation
Conditionally Include @Configuration Classes or @Bean Methods
Combining Java and XML Configuration
- Java-based Container Configuration
-
- Environment Abstraction
1.13.1. Bean Definition Profiles
Using @Profile
XML Bean Definition Profiles
Activating a Profile
Default Profile
1.13.2. PropertySource Abstraction
1.13.3. Using @PropertySource
1.13.4. Placeholder Resolution in Statements
- Environment Abstraction
-
- Registering a LoadTimeWeaver
-
- Additional Capabilities of the ApplicationContext
1.15.1. Internationalization using MessageSource
1.15.2. Standard and Custom Events
Annotation-based Event Listeners
Asynchronous Listeners
Ordering Listeners
Generic Events
1.15.3. Convenient Access to Low-level Resources
1.15.4. Convenient ApplicationContext Instantiation for Web Applications
1.15.5. Deploying a Spring ApplicationContext as a Java EE RAR File
- Additional Capabilities of the ApplicationContext
-
- The BeanFactory
1.16.1. BeanFactory or ApplicationContext?
- The BeanFactory