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

Spring相关的API-ApplicationContext的更多相关文章

  1. Spring中AOP相关的API及源码解析

    Spring中AOP相关的API及源码解析 本系列文章: 读源码,我们可以从第一行读起 你知道Spring是怎么解析配置类的吗? 配置类为什么要添加@Configuration注解? 谈谈Spring ...

  2. Spring配置文件详解 - applicationContext.xml文件路径

    spring的配置文件applicationContext.xml的默认地址在WEB-INF下,只要在web.xml中加入代码 org.springframework.web.context.Cont ...

  3. Spring配置文件详解 – applicationContext.xml文件路径

    Spring配置文件详解 – applicationContext.xml文件路径 Java编程                 spring的配置文件applicationContext.xml的默 ...

  4. 框架源码系列十一:事务管理(Spring事务管理的特点、事务概念学习、Spring事务使用学习、Spring事务管理API学习、Spring事务源码学习)

    一.Spring事务管理的特点 Spring框架为事务管理提供一套统一的抽象,带来的好处有:1. 跨不同事务API的统一的编程模型,无论你使用的是jdbc.jta.jpa.hibernate.2. 支 ...

  5. Spring相关BUG

    今天从云开发平台上生成的代码报Spring相关的错误. 我找到第一处错误,整理如下: org.springframework.beans.factory.BeanCreationException: ...

  6. Spring入门篇——第6章 Spring AOP的API介绍

    第6章 Spring AOP的API介绍 主要介绍Spring AOP中常用的API. 6-1 Spring AOP API的Pointcut.advice概念及应用 映射方法是sa开头的所有方法 如 ...

  7. Spring Boot & Restful API 构建实战!

    作者:liuxiaopeng https://www.cnblogs.com/paddix/p/8215245.html 在现在的开发流程中,为了最大程度实现前后端的分离,通常后端接口只提供数据接口, ...

  8. Spring相关jar说明

    Spring整合使用说明 一.只是使用spring框架 dist\spring.jar lib\jakarta-commons\commons-logging.jar 如果使用到了切面编程(AOP), ...

  9. Spring的核心api和两种实例化方式

    一.spring的核心api Spring有如下的核心api BeanFactory :这是一个工厂,用于生成任意bean.采取延迟加载,第一次getBean时才会初始化Bean Applicatio ...

  10. 搭建Spring相关框架后,配置信息文件头部出现红色小×错误。

    问题描述: 在搭建关于Spring相关框架的时候,在applicationContext.xml配置文件和servlet-mvc.xml配件文件的头部会出现一个红色的小X错误: 错误描述: Refer ...

随机推荐

  1. Create Table 实例

    1 USE databaseWeb; 2 DROP TABLE IF EXISTS tb_person; 3 CREATE TABLE tb_person( 4 id INTEGER AUTO_INC ...

  2. RabbitMQ Go客户端教程2——任务队列/工作队列

    本文翻译自RabbitMQ官网的Go语言客户端系列教程,本文首发于我的个人博客:liwenzhou.com,教程共分为六篇,本文是第二篇--任务队列. 这些教程涵盖了使用RabbitMQ创建消息传递应 ...

  3. Python knife 一款伪菜刀

    Python knife ​ 一款伪菜刀. ​ 设计之初,本想只写个命令行的就可以了,但又想与众不同,想用python写代码,又不想用c#写前端(c#太卡了),万分无奈之下,找到一个替代品,Pyqt, ...

  4. w3af漏扫的基本使用

    一.安装 apt安装 apt-get update apt-get install -y w3af 出现无法定位软件包 源码安装 sudo apt-get install git sudo apt-g ...

  5. 羽夏看Win系统内核——异常篇

    写在前面   此系列是本人一个字一个字码出来的,包括示例和实验截图.由于系统内核的复杂性,故可能有错误或者不全面的地方,如有错误,欢迎批评指正,本教程将会长期更新. 如有好的建议,欢迎反馈.码字不易, ...

  6. [WPF] 假装可变字体

    1. 可变字体 上图中的两个动画,一个文字直接变粗,一个渐渐变粗,我觉得后者会更有趣.但普通的字体可达不到这种效果,例如微软雅黑,无论怎么调整它的 FontWeight,实际上它也只有三种粗细: 这时 ...

  7. ::before和:after中的的双冒号和单冒号有什么区别及这两个伪元素的作用

    ::before和:after中的的双冒号和单冒号有什么区别及这两个伪元素的作用 单冒号(:)用于CSS3伪类,双冒号(::)用于CSS3伪元素(伪元素由双冒号和伪元素名称组成),为了兼容已有的伪元素 ...

  8. C++ 文件加解密

    通过文件二进制数据 与密钥进行异或处理,可加密文件 #ifndef __ENCRYPT__HEAD__ #define __ENCRYPT__HEAD__ #include <fstream&g ...

  9. Spring支持的ORM?

    Spring支持以下ORM: Hibernate iBatis JPA (Java Persistence API) TopLink JDO (Java Data Objects) O

  10. Elasticsearch 在部署时,对 Linux 的设置有哪些优化方法 ?

    1.关闭缓存 swap; 2.堆内存设置为:Min(节点内存/2, 32GB); 3.设置最大文件句柄数: 4.线程池+队列大小根据业务需要做调整: 5.磁盘存储 raid 方式--存储有条件使用 R ...