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. 命令行安装django以及新建项目及应用

    1:安装django项目,使用pip命令进行安装,默认安装的是最高版本,可以使用pip install django==1.1.11进行指定版本安装 2:新建django项目 2.1:首先切换到创建项 ...

  2. Numpy库基础___五

    Numpy数据存取 •NumPy的随机数函数 a = np.random.rand(1,2,3) print(a) #[[[0.03339719 0.72784732 0.47527802] # [0 ...

  3. 阿里云pypi软件包预警

    镜像下载.域名解析.时间同步请点击阿里云开源镜像站 背景 Python库的官方仓库pypi允许开发者自由上传软件包,这会导致某些攻击者利用这点构造恶意包进行供应链攻击,在用户安装包或者引入包时触发恶意 ...

  4. ssh中pam模块造成认证失败

    由于编译参数增加了pam认证 安装后发现这个模块没启用 vim /etc/ssh/sshd_config UsePAM yes 将这个模块打开后就ok了

  5. 自定义 Django admin 组件

    摘要:学习 Django admin 组件,仿照源码的逻辑,自定义了一个简易的 stark 组件,实现类似 admin 的功能. 可自动生成 url 路由,对于model 有与之相应的配置类对象,可进 ...

  6. 4月3日 python学习总结

    1. 列表生成器 l=['egg%s' %i for i in range(100) if i>20 ] print(l) 若将 [ ] 换成 ( ),则为生成器表达式,结果是一个迭代器 #求文 ...

  7. Flask(Jinja2) 服务端模板注入漏洞

    原理 参考文章: https://www.blackhat.com/docs/us-15/materials/us-15-Kettle-Server-Side-Template-Injection-R ...

  8. SQL注入工具sqlmap的使用

    sqlmap使用 测试注入点 sqlmap -u "URL" 爆数据库 sqlmap -u "URL" --dbs 查看当前库 sqlmap -u " ...

  9. 添加ico图标

    1. 先添加资源文件XXX.Ico,然后引用的时候用如下代码即可. Icon ico=Properties.Resources.XXX;

  10. 洛谷 P1020 [NOIP1999 普及组] 导弹拦截

    Coidng #include <iostream> #include <algorithm> #include <cstring> #include <ve ...