区别

BeanFactory:

	Spring里面最低层的接口,提供了最简单的容器的功能,只提供了实例化对象和拿对象的功能

	BeanFactory在启动的时候不会去实例化Bean,中有从容器中拿Bean的时候才会去实例化

ApplicationContext:

	应用上下文,继承BeanFactory接口,它是Spring的一各更高级的容器,提供了更多的有用的功能

		1) 国际化(MessageSource)

		2) 访问资源,如URL和文件(ResourceLoader)

		3) 载入多个(有继承关系)上下文 ,使得每一个上下文都专注于一个特定的层次,比如应用的web层  

		4) 消息发送、响应机制(ApplicationEventPublisher)

		5) AOP(拦截器)

	ApplicationContext在启动的时候就把所有的非延迟加载Bean全部实例化了。它还可以为Bean配置 lazy-init=true 来让Bean延迟实例化

国际化(MessageSource)

<!-- 资源国际化 -->
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>properties/messages</value> <!-- proerties包下的以messages为主要名称的properties文件 -->
</list>
</property>
</bean>

Spring访问资源(ResourceLoader)

ApplicationContext acxt =new ClassPathXmlApplicationContext("/applicationContext.xml");

1.通过虚拟路径来存取:当资源位于CLASSPATH路径下时,可以采用这种方式来存取。

	Resource resource = acxt.getResource("classpath:messages_en_CN.properties");

2.通过绝对路径存取资源文件。

	Resource resource = acxt.getResource("file:F:/messages_en_CN.properties");

3.相对路径读取资源文件。

	Resource resource = acxt.getResource("/messages_en_CN.properties");

Spring载入多个上下文

方法一:

	<import resource="applicationContext.xml"/>

方法二:

	<context-param>
<param-name>contextConfigLocation</param-name> <param-value>
classpath:applicationContext-security.xml,applicationContext-dao.xml,applicationContext-Service.xml
</param-value>
</context-param> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

Spring的AOP(常用的是拦截器)

一般拦截器都是实现HandlerInterceptor,其中有三个方法preHandle、postHandle、afterCompletion

	1. preHandle:执行controller之前执行

	2. postHandle:执行完controller,return modelAndView之前执行,主要操作modelAndView的值

	3. afterCompletion:controller返回后执行

配置:

	<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**" />
<mvc:exclude-mapping path="/login"/>
<mvc:exclude-mapping path="/logout"/>
<ref bean="interceptor" />
</mvc:interceptor>
</mvc:interceptors> public class Interceptor extends HandlerInterceptorAdapter { @Override
public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler)
throws Exception {
return true;
}
}

BeanFactory 和 ApplicationContext 区别的更多相关文章

  1. Spring加载xml配置文件的方式(BeanFactory和ApplicationContext区别)

    描述 大家都知道Java读普通文件是通过Basic I/O 中的InputStream.OutStream.Reader.Writer 等实现的.在spring 框架中,它是怎样识别xml这个配置文件 ...

  2. Spring之BeanFactory与ApplicationConText区别

    使用BeanFactory从xml配置文件加载bean: import org.springframework.beans.factory.xml.XmlBeanFactory; import org ...

  3. day38 05-Spring的BeanFactory与ApplicationContext区别

    ApplicationContext怎么知道它是一个工厂呢? BeanFactory也可以做刚才那些事情,只不过ApplicationContext对它有扩展.ApplicationContext间接 ...

  4. BeanFactory和ApplicationContext的作用和区别

    BeanFactory和ApplicationContext的作用和区别 作用: 1. BeanFactory负责读取bean配置文档,管理bean的加载,实例化,维护bean之间的依赖关系,负责be ...

  5. spring中的BeanFactory与ApplicationContext的作用和区别?

    BeanFactory类关系继承图 1. BeanFactory类结构体系: BeanFactory接口及其子类定义了Spring IoC容器体系结构,由于BeanFactory体系非常的庞大和复杂, ...

  6. Spring中BeanFactory与ApplicationContext的区别

    BeanFactory:Bean工厂接口,是访问Spring Bean容器的根接口,基本Bean视图客户端.从其名称上即可看出其功能,即实现Spring Bean容器的读取. ApplicationC ...

  7. BeanFactory 和 ApplicationContext的区别

    今天在网上查资料无意中看到这一行代码 BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext ...

  8. Spring中的BeanFactory和ApplicationContext的区别

    我用一个例子去测试BeanFactory和ApplicationContext的区别 首先建立一个bean public class User { //声明无参构造,打印一句话,监测对象创建时机 pu ...

  9. BeanFactory和ApplicationContext的区别+部分Spring的使用

    BeanFactory和ApplicationContext的区别 ApplicationContext 方式加载:创建容器的同时 容器初始化,容器所有的bean创建完毕   Spring容器中获取一 ...

随机推荐

  1. element-UI select 踩过的坑和解决办法

    今天遇到了一个bug,就是在使用element-UI的select框时,当选中值,会触发@change事件,下拉框消失,但是这时候select框还是处于获取焦点状态.可以看到select框还是处于颜色 ...

  2. Codeforces 1175F 尺取法 性质分析

    题意:给你一个数组,问有多少个区间,满足区间中的数构成一个排列. 思路(大佬代码):我们发现,一个排列一定含有1,所以我们不妨从1开始入手计算构成排列的区间个数.对于每个扫描到的1(假设处于位置i), ...

  3. 【CSS】水平居中与垂直居中

    有宽度的div水平居中 1.左右margin设为auto即可 .center { width: 960px; margin-left: auto; margin-right: auto; } 2.绝对 ...

  4. Android各种蓝牙设备的UUID(转)

    转自:http://www.14blog.com/archives/481 UUID是“Universally Unique Identifier”的简称,通用唯一识别码的意思.对于蓝牙设备,每个服务 ...

  5. 【Luogu】【关卡2-8】广度优先搜索(2017年10月)

    任务说明:广度优先搜索可以用来找有关“最短步数”的问题.恩,也可以用来“地毯式搜索”.

  6. vue 表格 多选 换页保存前一页的状态

    表格多选 点击下一页,上一页的状态没消失. 在表格 添加 row-key="id" 在表格行里添加 reserve-selection

  7. c# 转16进制

    1.byte[] 转换16进制字符串 1.1 BitConverter方式 var str = DateTime.Now.ToString(); var encode = Encoding.UTF8; ...

  8. 基于Flink和规则引擎的实时风控解决方案

    案例与解决方案汇总页:阿里云实时计算产品案例&解决方案汇总 对一个互联网产品来说,典型的风控场景包括:注册风控.登陆风控.交易风控.活动风控等,而风控的最佳效果是防患于未然,所以事前事中和事后 ...

  9. $\mathcal{CSP-S}$,私は来ています

    记事本 开个坑.背包dp我是真的一点也不会了... NOIP2014飞扬的小鸟 NOIP2018货币系统 11-4:$Countdown$ $to$ $the$ $tenth$ $day$ 上午 困的 ...

  10. delphi与javascript互通

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...