spring-01 核心API

核心API

  1. api整体了解,之后不使用,在学习过程需要。

  1. BeanFactory :这是一个工厂,用于生成任意bean。

       采取延迟加载,第一次getBean时才会初始化Bean

  1. ApplicationContext:是BeanFactory的子接口,功能更强大。(国际化处理、事件传递、Bean自动装配、各种不同应用层的Context实现)。当配置文件被加载,就进行对象实例化。

       ClassPathXmlApplicationContext 用于加载classpath(类路径、src)下的xml

              加载xml运行时位置 --> /WEB-INF/classes/...xml

       FileSystemXmlApplicationContext 用于加载指定盘符下的xml

              加载xml运行时位置 --> /WEB-INF/...xml

                     通过java web ServletContext.getRealPath() 获得具体盘符

 

    @Test

    public void demo02(){

        //使用BeanFactory  --第一次条用getBean实例化

        String xmlPath = "com/itheima/b_di/beans.xml";

       

        BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource(xmlPath));

       

        BookService bookService = (BookService) beanFactory.getBean("bookServiceId");

       

        bookService.addBook();

       

    }

 

猜你喜欢

转载自blog.csdn.net/qq_35187942/article/details/87937773