zoukankan      html  css  js  c++  java
  • Spring学习一: Ioc容器

    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); } }
    复制代码
  • 相关阅读:
    P1246 编码
    P2638 安全系统
    P3913 车的攻击
    P2789 直线交点数
    What?100%基于深度强化学习的对冲基金
    AI | 重磅推荐!哥大开源“FinRL”:一个用于量化金融自动交易的深度强化学习库
    神经霍克斯过程:一个基于神经网络的自调节多变量点过程
    量化都玩IPU了?Man Group-Oxford研究所给你答案
    为什么数字资产生态系统能够增长到2万亿美元以上?
    ICML 获奖者陆昱成:去中心化机器学习的理论极限在哪里?
  • 原文地址:https://www.cnblogs.com/guanbin-529/p/13568841.html
Copyright © 2011-2022 走看看