当前位置:网站首页>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 .
边栏推荐
- VIM asynchronous problem
- [buuctf.reverse] 151_[FlareOn6]DnsChess
- Some suggestions for interface design
- js 3D爆炸碎片图片切换js特效
- LeetCode+ 81 - 85 单调栈专题
- 【微服务|SCG】Predicate的使用
- Solution of 5g unstable 5g signal often dropped in NetWare r7000 Merlin system
- RFID仓库管理系统解决方案有哪些功能模块
- hash 表的概念及应用
- Procurement in software development
猜你喜欢
Foxit pdf editor v10.1.8 green version
伦敦银走势图分析的新方法
Huawei ENSP simulator configures DHCP for router
RFID仓储管理系统解决方案的优点
MySQL - database query - use of aggregate function, aggregate query, grouping query
华为ensp模拟器 配置ACL访问控制列表
Pytorch---使用Pytorch实现LinkNet进行语义分割
PS竖排英文和数字文字怎么改变方向(变竖直显示)
华为ensp模拟器 DNS服务器的配置
admas零件名重复
随机推荐
黄金k线图中的三角形有几种?
[observation] Lenovo: 3x (1+n) smart office solution, releasing the "multiplier effect" of office productivity
为什么说不变模式可以提高性能
Sword finger offer II 80-100 (continuous update)
测试用例 (TC)
RFID仓储管理系统解决方案的优点
torch.tensor和torch.Tensor的区别
2021 CCPC 哈尔滨 B. Magical Subsequence(思维题)
Test case (TC)
Poster cover of glacier
杰理之AD 系列 MIDI 功能说明【篇】
JS卡牌样式倒计时天数
华为模拟器ensp常用命令
ACM组合计数入门
企业数字化转型最佳实践案例:基于云的数字化平台系统安全措施简介与参考
Detailed explanation of multi-mode input event distribution mechanism
【1200. 最小绝对差】
Huawei simulator ENSP common commands
【申博攻略】六.如何联系心仪的博导
[solution] paddlepaddle 2 X call static graph mode