Spring相关的API-ApplicationContext
2024-09-17 22:11:21
1.ClassPathXmlApplicationContext
它是从类的根路径下加载配置文件推荐使用这种
public class UserController {
public static void main(String[] args) {
ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
UserService service = (UserService) context.getBean("userService");
service.sava();
}
}
**2.**FileSystemXmlApplicationContext(用的不多)
它是从磁盘路径上加载配置文件,配置文件可以在磁盘的任意位置
public class UserController {
public static void main(String[] args) {
ApplicationContext context=new FileSystemXmlApplicationContext("D:\\spring\\src\\main\\resources\\applicationContext.xml");
UserService service = (UserService) context.getBean("userService");
service.sava();
}
}
3.AnnotationConfigApplicationContext
当使用注解配置容器对象时,需要使用此类来创建spring容器,它来读取注解
public class UserController {
public static void main(String[] args) {
ApplicationContext context=new AnnotationConfigApplicationContext(SpringConfiguration.class);
UserService service = (UserService) context.getBean("userService");
service.sava();
}
}
最新文章
- 如何用ZBrush快速绘制身体
- android之数据库SQLite(一)
- RabbitMQ介绍3 - 运行和管理RabbitMQ
- mysql router 自动failover测试
- jQuery get/post区别及contentType取值
- .NET设计模式系列文章
- 如何设置让网站禁止被爬虫收录?robots.txt
- glusterfs4.0.1 mempool 分析笔记
- 【普及篇】通信能力API及其前景分析
- Springboot 配置 ssl 实现HTTPS 请求 &; Tomcat配置SSL支持https请求
- 期货大赛项目|四,MVC的数据验证
- 01:golang开发环境
- 算术运算,赋值运算,if语句,while,continue语句
- Azure SQL 数据库仓库Data Warehouse (3) DWU
- [原创]解决IPCH关闭后可能引发的无法调试的BUG
- orcale 之 数据完整性约束
- IDEA的使用方法(三)(改变字体主题)
- SAP-ABAP系列 第一篇SAP简介
- 《Image-to-Image Translation with Conditional Adversarial Networks》论文笔记
- 用js采集网页数据并插入数据库最快的方法
热门文章
- Jira8.0.2安装及破解
- LGP3349口胡
- 写给开发人员的实用密码学(七)—— 非对称密钥加密算法 RSA/ECC
- java反射之java 泛型的本质
- 如何将docker 镜像上传到docker hub仓库
- Div+CSS 定位 Position
- Arcmap软件报错:This application cannot run under a virtual machine arcmapr, 但是你并没有使用虚拟机
- .user.ini文件构成的PHP后门
- file_put_contents利用技巧(php://filter协议)
- Minikube使用文档