zoukankan      html  css  js  c++  java
  • spring中的BeanFactory与ApplicationContext的作用和区别?

    作用:

    1. BeanFactory负责读取bean配置文档,管理bean的加载,实例化,维护bean之间的依赖关系,负责bean的声明周期。
    2. ApplicationContext除了提供上述BeanFactory所能提供的功能之外,还提供了更完整的框架功能:

    a. 国际化支持
    b. 资源访问:Resource rs = ctx. getResource(“classpath:config.properties”), “file:c:/config.properties”
    c. 事件传递:通过实现ApplicationContextAware接口
    3. 常用的获取ApplicationContext的方法:
    FileSystemXmlApplicationContext:从文件系统或者url指定的xml配置文件创建,参数为配置文件名或文件名数组
    ClassPathXmlApplicationContext:从classpath的xml配置文件创建,可以从jar包中读取配置文件
    WebApplicationContextUtils:从web应用的根目录读取配置文件,需要先在web.xml中配置,可以配置监听器或者servlet来实现

    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
    <servlet-name>context</servlet-name>
    <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>


    这两种方式都默认配置文件为web-inf/applicationContext.xml,也可使用context-param指定配置文件

    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/myApplicationContext.xml</param-value>
    </context-param>
  • 相关阅读:
    模板的导入和继承
    图解从 URL 到网页通信原理
    HTTP协议详细介绍
    django的模型层
    LeetCode3-Longest Substring Without Repeating Characters
    LeetCode2-Add Two Numbers
    LeetCode1-Two Sum
    面试干货整理
    VS中使用QT调用R脚本
    MFC DLL 资源模块句柄切换[转]
  • 原文地址:https://www.cnblogs.com/wdmwj626/p/4771988.html
Copyright © 2011-2022 走看看