当前位置:网站首页>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 .
边栏推荐
- 嵌入式TC 测试用例
- 吐槽 B 站收费,是怪它没钱么?
- y56.第三章 Kubernetes从入门到精通 -- 业务镜像版本升级及回滚(二九)
- MySQL --- 数据库查询 - 聚合函数的使用、聚合查询、分组查询
- Actual combat simulation │ JWT login authentication
- Advantages of semantic tags and block level inline elements
- Play the music of youth
- 实战模拟│JWT 登录认证
- 网件r7000梅林系统虚拟内存创建失败,提示USB磁盘读写速度不满足要求解决办法,有需要创建虚拟内存吗??
- Explication détaillée du mécanisme de distribution des événements d'entrée multimodes
猜你喜欢

NetWare r7000 Merlin system virtual memory creation failed, prompting that the USB disk reading and writing speed does not meet the requirements. Solution, is it necessary to create virtual memory??

render函数与虚拟dom

Hwinfo hardware detection tool v7.26 green version

UTF encoding and character set in golang

Foxit pdf editor v10.1.8 green version

Quelques suggestions pour la conception de l'interface

华为ensp模拟器实现通信安全(交换机)

Advantages of RFID warehouse management system solution

Golang中UTF编码和字符集
![[1200. Différence absolue minimale]](/img/fa/4ffbedd8f24c75a20d3eaeaf0430ae.png)
[1200. Différence absolue minimale]
随机推荐
Huawei ENSP simulator configures ACL access control list
Browser render page pass
Introduction to pressure measurement of JMeter
Automatic generation of interface automatic test cases by actual operation
网络命名空间
华为模拟器ensp常用命令
测试员的算法面试题-找众数
分析伦敦银走势图的技巧
Idea case shortcut
为什么说不变模式可以提高性能
[1200. Minimum absolute difference]
acwing 3302. 表达式求值
Quelques suggestions pour la conception de l'interface
杰理之增加进关机前把触摸模块关闭流程【篇】
WGCNA分析基本教程总结
After inserting a picture into word, there is a blank line above the picture, and the layout changes after deletion
Huawei ENSP simulator realizes communication security (switch)
黄金k线图中的三角形有几种?
Embedded TC test case
Hwinfo hardware detection tool v7.26 green version