当前位置:网站首页>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 .
边栏推荐
- Foxit pdf editor v10.1.8 green version
- Huawei ENSP simulator layer 3 switch
- Huawei ENSP simulator realizes communication security (switch)
- 华为ensp模拟器 实现多个路由器的设备可以相互访问
- 搭建一个仪式感点满的网站,并内网穿透发布到公网 1/2
- y56.第三章 Kubernetes从入门到精通 -- 业务镜像版本升级及回滚(二九)
- 偷窃他人漏洞报告变卖成副业,漏洞赏金平台出“内鬼”
- render函数与虚拟dom
- Browser render page pass
- __init__() missing 2 required positional arguments 不易查明的继承错误
猜你喜欢

Summary of the mistakes in the use of qpainter in QT gobang man-machine game

Some suggestions for interface design

colResizable.js自动调整表格宽度插件

Huawei ENSP simulator configures ACL access control list

Configuration of DNS server of Huawei ENSP simulator

Detailed explanation of multi-mode input event distribution mechanism

【服务器数据恢复】某品牌服务器存储raid5数据恢复案例

shp数据制作3DTiles白膜

华为ensp模拟器 实现多个路由器的设备可以相互访问

网件r7000梅林系统虚拟内存创建失败,提示USB磁盘读写速度不满足要求解决办法,有需要创建虚拟内存吗??
随机推荐
ACM组合计数入门
Detailed explanation of multi-mode input event distribution mechanism
Summary of the mistakes in the use of qpainter in QT gobang man-machine game
五子棋 上班摸鱼工具 可局域网/人机
【微服务|SCG】Predicate的使用
[Shenbo introduction] VI How to contact your favorite doctoral tutor
伦敦银走势图分析的新方法
【解决方案】PaddlePaddle 2.x调用静态图模式
After inserting a picture into word, there is a blank line above the picture, and the layout changes after deletion
Routing configuration and connectivity test of Huawei simulator ENSP
企业数字化转型最佳实践案例:基于云的数字化平台系统安全措施简介与参考
JS closure
Idea case shortcut
杰理之AD 系列 MIDI 功能说明【篇】
Render function and virtual DOM
Advantages of semantic tags and block level inline elements
Hands on deep learning (III) -- convolutional neural network CNN
杰理之AD 系列 MIDI 功能说明【篇】
Day24:文件系统
[1200. Minimum absolute difference]