当前位置:网站首页>Difference between ApplicationContext and beanfactory (MS)
Difference between ApplicationContext and beanfactory (MS)
2022-07-04 21:14:00 【Youcan.】
1. In terms of inheritance ,BeanFactory yes Of Parent class .BeanFactory It just provides Basic operation Bean Methods ,ApplicationContext In addition to having the basic operations of the parent class , It also provides Own unique functions .
2. In terms of performance ,ApplicationContext yes One-time loading And initialize all Bean object , however BeanFactory yes Which one do you need Bean Just to go Load which Bean.
ApplicationContext Is in At the time of creation It'll take all of bean initialization , for the first time Use bean When fast , Startup is slow , But it may cause Waste of resources .BeanFactory Don't waste Any resources , First load bean Compare slow .
import beans.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @program: first-spring
* @description: adopt ApplicationContext To get the object
* @author: DRY
* @create: 2022-07-03 12:47
**/
public class App {
public static void main(String[] args) {
//1. Get the context object first
ApplicationContext context =
new ClassPathXmlApplicationContext("spring-config.xml");
//2. from spring Get... From context object bean
User user = (User)context.getBean("user");
//3. Use object ( May not be used )
user.sayHi(" Zhang Dan ");
}
}
import beans.User;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
/**
* @program: first-spring
* @description: adopt BeanFactory To get spring Context object
* @author: DRY
* @create: 2022-07-03 13:06
**/
public class App2 {
public static void main(String[] args) {
//1. First get BeanFactory To get the object
BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("spring-config.xml"));
//2. obtain bean
User user = (User) beanFactory.getBean("user");
//3. Use bean
user.sayHi(" Li Si ");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- Indicates that a bean Object store to spring in ( There can be multiple bean label )-->
<bean id="user" class="beans.User"></bean>
</beans>
these two items. user Must remain the same .
边栏推荐
- 网络命名空间
- MySQL - database query - use of aggregate function, aggregate query, grouping query
- Redis:Redis配置文件相关配置、Redis的持久化
- [Shenbo introduction] VI How to contact your favorite doctoral tutor
- Huawei ENSP simulator layer 3 switch
- 【1200. 最小絕對差】
- 华为ensp模拟器实现通信安全(交换机)
- B站视频 声音很小——解决办法
- Poster cover of glacier
- Jmeter 之压测入门
猜你喜欢
【服务器数据恢复】某品牌服务器存储raid5数据恢复案例
Hands on deep learning (III) -- convolutional neural network CNN
Introduction to pressure measurement of JMeter
Huawei ENSP simulator configures ACL access control list
伦敦银走势图分析的新方法
6月“墨力原创作者计划”获奖名单公布!邀您共话国产数据库
Jmeter 之压测入门
Leetcode+ 81 - 85 monotone stack topic
多模输入事件分发机制详解
uniapp 富文本编辑器使用
随机推荐
torch.tensor和torch.Tensor的区别
偷窃他人漏洞报告变卖成副业,漏洞赏金平台出“内鬼”
[buuctf.reverse] 151_[FlareOn6]DnsChess
【1200. 最小絕對差】
杰理之AD 系列 MIDI 功能说明【篇】
colResizable.js自动调整表格宽度插件
Automatic insertion of captions in word
杰理之AD 系列 MIDI 功能说明【篇】
华为ensp模拟器 配置ACL访问控制列表
hash 表的概念及应用
接口設計時的一些建議
卷积神经网络在深度学习中新发展的5篇论文推荐
JS closure
华为ensp模拟器 实现多个路由器的设备可以相互访问
JS卡牌样式倒计时天数
HMS Core 统一扫码服务
网件r7000梅林系统5g不稳定 5g信号经常掉线解决方法
HWiNFO硬件检测工具v7.26绿色版
Vue cleans up the keepalive cache scheme in a timely manner
Leetcode+ 81 - 85 monotone stack topic