zoukankan      html  css  js  c++  java
  • Spring IOC

    Spring IOC

    --------------------------------------------------------------------------------------------------------------------------
    IOC控制反转
    
    IOC是DI的原理。依赖注入是向某个类或方法注入一个值,其中所用到的原理就是控制反转。Spring容器的初始化和加载的原理
    --------------------------------------------------------------------------------------------------------------------------
    
    
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.3.11.RELEASE</version>
        </dependency>
    </dependencies>
    
    // application-context.xml
    <bean id="testBeanService" class="com.zack.demo.TestBeanServiceImpl"/>
    
    
    public class TestBeanServiceImpl implements TestBeanService {
        public String getMessage() {
            return "a test bean";
        }
    }
    
    // ApplicationContext 是个接口
    public static void main(String[] args) {
        // 加载xml配置
        ApplicationContext context = 
            new ClassPathXmlApplicationContext("classpath:application.xml");
    
        // IOC获取Bean
        TestBeanService testBeanService = context.getBean(TestBeanService.class)
    }
    
    
    // 初始化IOC容器
    ClassPathXmlApplicationContext implements ApplicationContext
        refresh() //  刷新了整个context,加载所有Bean定义,创建对应的单例
            loadBeanDefinitions(); // 加载Bean的定义。实现交给了子类
    
    // 依赖注入
    context.getBean(TestBeanService.class)

    参考URL   https://www.jianshu.com/p/7b1746a86faf

  • 相关阅读:
    poj 1679 Prim判断次短路
    poj 3621 二分+spfa
    poj 3613 floyd + 快速幂
    poj3463 最短路和比最短路长1的路径数
    poj 3635 带花费的Dij+head优化
    poj 3013 SPFA
    POJ 2449 Dijstra + A* K短路
    webStorm关于ESlint6语法格式化解决方案
    Vue之 css3 样式重置 代码
    vue常用组件
  • 原文地址:https://www.cnblogs.com/webglcn/p/10953298.html
Copyright © 2011-2022 走看看