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();
}
}

最新文章

  1. 如何用ZBrush快速绘制身体
  2. android之数据库SQLite(一)
  3. RabbitMQ介绍3 - 运行和管理RabbitMQ
  4. mysql router 自动failover测试
  5. jQuery get/post区别及contentType取值
  6. .NET设计模式系列文章
  7. 如何设置让网站禁止被爬虫收录?robots.txt
  8. glusterfs4.0.1 mempool 分析笔记
  9. 【普及篇】通信能力API及其前景分析
  10. Springboot 配置 ssl 实现HTTPS 请求 & Tomcat配置SSL支持https请求
  11. 期货大赛项目|四,MVC的数据验证
  12. 01:golang开发环境
  13. 算术运算,赋值运算,if语句,while,continue语句
  14. Azure SQL 数据库仓库Data Warehouse (3) DWU
  15. [原创]解决IPCH关闭后可能引发的无法调试的BUG
  16. orcale 之 数据完整性约束
  17. IDEA的使用方法(三)(改变字体主题)
  18. SAP-ABAP系列 第一篇SAP简介
  19. 《Image-to-Image Translation with Conditional Adversarial Networks》论文笔记
  20. 用js采集网页数据并插入数据库最快的方法

热门文章

  1. Jira8.0.2安装及破解
  2. LGP3349口胡
  3. 写给开发人员的实用密码学(七)—— 非对称密钥加密算法 RSA/ECC
  4. java反射之java 泛型的本质
  5. 如何将docker 镜像上传到docker hub仓库
  6. Div+CSS 定位 Position
  7. Arcmap软件报错:This application cannot run under a virtual machine arcmapr, 但是你并没有使用虚拟机
  8. .user.ini文件构成的PHP后门
  9. file_put_contents利用技巧(php://filter协议)
  10. Minikube使用文档