zoukankan      html  css  js  c++  java
  • IOC(二)

    1.IOC思想基于IOC容器完成, IOC容器底层就是对象工厂

    2.Spring提供IOC容器实现的两种方式(两个接口):

      1).BeanFactory: IOC容器基本实现方式, 是Spring内部使用的接口, 不提供开发人员进行使用, 加载配置文件是不会创建对象, 在获取对象(使用)时才去创建对象;

      2).ApplicationContext: BeanFactory接口的子接口, 提供更多更强大的功能, 一般有开发人员进行使用, 加载配置文件时就会创建配置文件对象(这样就会让项目在开启时就创建好对象);

    3. ApplicationContext接口有两个实现类:

      

       两者的区别是:

      1).FileSystemXmlApplicationContext的路径参数以项目路径开始(从项目目录开始写路径):

    public class TestSpring5 {
    
        public static void main(String[] args){
    
            //1.加载Spring配置文件
            ApplicationContext context = new FileSystemXmlApplicationContext("conf/beans1.xml");
            //2.获取配置创建的对象
            User user = context.getBean("user", User.class);
    
            System.out.println(user);
            user.sayhi();
        }
    }

      2).ClassPathXmlApplicationContext的路径参数需写绝对路径(从盘符开始写, 前面加 file:):

    public class TestSpring5 {
    
        public static void main(String[] args){
    
            //1.加载Spring配置文件
            ApplicationContext context = new ClassPathXmlApplicationContext("file:D:\IntelliJIDEA\IntelliJ_IDEA_workspace\springDemo1015\conf\beans1.xml");
            //2.获取配置创建的对象
            User user = context.getBean("user", User.class);
    
            System.out.println(user);
            user.sayhi();
        }
    }
  • 相关阅读:
    字符串对比
    时间转换
    fJ字符串
    Codeforces 1526D
    HDU
    树链剖分入门
    AcWing 252. 树(点分治模版题)
    HDU-4487 Maximum Random Walk(概率dp)
    acwing 316 减操作(dp)
    CodeForces
  • 原文地址:https://www.cnblogs.com/Ryan368/p/13853964.html
Copyright © 2011-2022 走看看