Spring 容器:

     Spring 容器是Spring框架的核心。Spring容器将创建Bean对象实例,把它们联系在一起,配置它们,并管理它们整个生命周期从创建到销毁。Spring 容器通过依赖注入(DI)将它们组成一个应用程序组件。这些bean对象我们称为Spring beans。

    通过配置元数据指令,Spring容器知道对那些对象进行实例化、配置、组装。配置元数据可以通过XML、Java注解或Java代码来实现。下图是Spirn如何工作的高效图,Spring Ioc容器通过Java POJO(Plain Old Java Object)类和配置元数据生成完全配置。

Spring 框架提供两种不同类型的容器:

1.BeanFactory容器

  官网API:The BeanFactory interface provides an advanced configuration mechanism capable of managing any type of object。

翻译:BeanFactory接口提供一个高效配置机制可以管理任何类型的对象

2.ApplicationContext容器

官网API: ApplicationContext is a sub-interface of BeanFactory. It adds easier integration with Spring’s AOP features; message resource handling (for    use in internationalization), event publication; and application-layer specific contexts such as the WebApplicationContext for use in web applications。

翻译:ApplicationContext接口是BeanFactory接口的子接口,增加更容易集成Spring的AOP功能;信息资源处理(用于国际化),事件发布;和应用程序层特定上下文如WebApplicationContext用于web应用程序。

基于xml元数据配置Spring Ioc容器实现代码示例:

package com.test;

import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import com.test.service.NarCodeService; public class Spring {
ApplicationContext applicationContext = null; @Before
public void ApplicationContextInit() {
//创建一个ApplicationContext容器
applicationContext = new ClassPathXmlApplicationContext(new String[]{"test1-service.xml"});
System.out.println(applicationContext);
} }

最新文章

  1. MariaDB的GTID复制和多源复制
  2. jenkins使用git SCM时changelog乱码(Jenkins部署在Linux上,任务在Windows Slave上构建)
  3. 小白的vue学习路程
  4. 对于类的双重调用的demo
  5. getline函数的用法
  6. BZOJ 3999 旅游
  7. 【M29】引用计数
  8. WCF - 绑定
  9. codeforces 589F. Gourmet and Banquet 二分+网络流
  10. JSON的使用小结
  11. Linux多线程编程——线程的创建与退出
  12. mac 连接linux服务器,用scp命令实现本地文件与服务器文件之间的互相传输
  13. scrollview中edittext失去焦点问题
  14. virtualenvwrappers pipreqs 踩坑
  15. 关于Spring Data JPA更新部分字段的问题
  16. WebStorm开发React项目,修代码之后运行的项目不更新
  17. Kruskal算法:最小生成树
  18. final、finally、finalize的用法
  19. MySQL C API(23)
  20. 【PyTorch深度学习60分钟快速入门 】Part0:系列介绍

热门文章

  1. CapstoneCS5265|TYPEC转HDMI 4K60HZ转换方案设计|CS5265功能介绍
  2. ORW-测信道攻击
  3. Android开发 SeekBar(拖动条)的使用
  4. 【MySQL作业】MySQL函数——美和易思数学函数和控制流函数应用习题
  5. Hadoop单点安装(伪分布式)
  6. CSS基础 水平居中案例
  7. CAP 6.0 版本发布通告 - 支持 OpenTelemetry
  8. minio文件上传与下载
  9. Python_多任务:进程、线程、协程
  10. Sentry 企业级数据安全解决方案 - Relay PII 和数据清理