Spring中BeanFactory和ApplicationContext的作用和区别(推荐)
程序员文章站
2022-07-06 08:58:42
作用:1.beanfactory负责读取bean配置文档,管理bean的加载,实例化,维护bean之间的依赖关系,负责bean的声明周期。2.applicationcontext除了提供上述beanf...
作用:
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>
总结
到此这篇关于spring中beanfactory和applicationcontext的作用和区别的文章就介绍到这了,更多相关spring中beanfactory和applicationcontext内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
推荐阅读
-
Python中print和return的作用及区别解析
-
Spring框架中 @Autowired 和 @Resource 注解的区别
-
关于vuejs中v-if和v-show的区别及v-show不起作用问题
-
浅谈es6中export和export default的作用及区别
-
spring注解中的@Autowired和@Component基本作用
-
Spring中BeanFactory和ApplicationContext的作用和区别(推荐)
-
Spring中FactoryBean的作用和实现原理
-
Excel中SEARCH和FIND函数的作用及其区别介绍
-
Mysql中的table engine及各种engine的区别和作用讲解
-
java中形参,实参,成员变量,局部变量,构造方法的作用和区别