• Day 84


    _Spring技术IoC入门案例

    1. 管理什么?(Service 与 Dao)

    2. 如何将被管理的对象告知IoC容器?(配置)

    3. 被管理的对象交给IoC容器,如何获取到IoC容器?(接口)

    4. IoC容器得到后,如何从容器中获取bean?(接口方法)

    5. 在这里插入图片描述

    6. 两个实现类包的文件java代码为:

      • 在这里插入图片描述

      • 在这里插入图片描述

    7. 测试类文件中的java代码为:

      • package Application;
        
        import dao.impl.BookDaoImpl;
        import org.springframework.context.ApplicationContext;
        import org.springframework.context.support.ClassPathXmlApplicationContext;
        import org.springframework.context.support.GenericApplicationContext;
        import service.Impl.BookServiceImpl;
        
        public class App_02 {
            public static void main(String[] args) {
                // 加载配置文件
                ApplicationContext apt = new ClassPathXmlApplicationContext("applicationContext.xml");
        
                // 获取资源
        //        BookDaoImpl bookDao = (BookDaoImpl) apt.getBean("BookDao");
        //        bookDao.run();
        
                BookServiceImpl bookService = (BookServiceImpl) apt.getBean("BookService");
                bookService.run();
        
            }
        }
        ============================================
        this is BookService
        this is BookDao
        
        Process finished with exit code 0
        
        • 1
        • 2
        • 3
        • 4
        • 5
        • 6
        • 7
        • 8
        • 9
        • 10
        • 11
        • 12
        • 13
        • 14
        • 15
        • 16
        • 17
        • 18
        • 19
        • 20
        • 21
        • 22
        • 23
        • 24
        • 25
        • 26
        • 27

    _Spring技术DI案例

    1. 基于IoC管理bean

    2. Service中使用new形式创建的Dao对象是否保留?(否)

    3. Service中需要Dao对象如何进入到Service中?(提供方法)

    4. 在这里插入图片描述

    5. 在这里插入图片描述

    6. 在test文件中的java代码不需要做变化

      • package Application;
        
        import org.springframework.context.ApplicationContext;
        import org.springframework.context.support.ClassPathXmlApplicationContext;
        import service.Impl.BookServiceImpl;
        
        public class App_02 {
            public static void main(String[] args) {
                // 加载配置文件
                ApplicationContext apt = new ClassPathXmlApplicationContext("applicationContext.xml");
        
                // 获取资源
                BookServiceImpl bookService = (BookServiceImpl) apt.getBean("bookService");
                bookService.run();
            }
        }
        =========================================
        this is BookService
        this is BookDao
        
        Process finished with exit code 0
        
        
        • 1
        • 2
        • 3
        • 4
        • 5
        • 6
        • 7
        • 8
        • 9
        • 10
        • 11
        • 12
        • 13
        • 14
        • 15
        • 16
        • 17
        • 18
        • 19
        • 20
        • 21
        • 22
      • 能够输出两条信息说明在BookDaoImpl与BookServiceImpl之间建立的连接没有问题

    _Spring技术bean基础配置

    1. 在这里插入图片描述

    2. 在这里插入图片描述

  • 相关阅读:
    C Primer Plus(6) 中文版 第7章 C控制语句:分支和跳转 7.8 goto语句 7.9 关键概念 7.10 本章小结
    基于ssm的智慧农贸信息化管理平台-计算机毕业设计源码
    编码器的原理以及在arduino中的使用
    redis数据库的下载安装/免安装版
    【C++链表】
    matplotlib如何保存高分辨率图(亲测)
    SpringMVC——Controller如何将数据响应给客户端
    R语言在生态环境领域中的应用
    猿创征文|嵌入式高效开发5款工具推荐!
    C++ RAII在HotSpot VM中的重要应用
  • 原文地址:https://blog.csdn.net/ALVIS_108/article/details/126192692