Spring相关的API-ApplicationContext
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的更多相关文章
- Spring中AOP相关的API及源码解析
Spring中AOP相关的API及源码解析 本系列文章: 读源码,我们可以从第一行读起 你知道Spring是怎么解析配置类的吗? 配置类为什么要添加@Configuration注解? 谈谈Spring ...
- Spring配置文件详解 - applicationContext.xml文件路径
spring的配置文件applicationContext.xml的默认地址在WEB-INF下,只要在web.xml中加入代码 org.springframework.web.context.Cont ...
- Spring配置文件详解 – applicationContext.xml文件路径
Spring配置文件详解 – applicationContext.xml文件路径 Java编程 spring的配置文件applicationContext.xml的默 ...
- 框架源码系列十一:事务管理(Spring事务管理的特点、事务概念学习、Spring事务使用学习、Spring事务管理API学习、Spring事务源码学习)
一.Spring事务管理的特点 Spring框架为事务管理提供一套统一的抽象,带来的好处有:1. 跨不同事务API的统一的编程模型,无论你使用的是jdbc.jta.jpa.hibernate.2. 支 ...
- Spring相关BUG
今天从云开发平台上生成的代码报Spring相关的错误. 我找到第一处错误,整理如下: org.springframework.beans.factory.BeanCreationException: ...
- Spring入门篇——第6章 Spring AOP的API介绍
第6章 Spring AOP的API介绍 主要介绍Spring AOP中常用的API. 6-1 Spring AOP API的Pointcut.advice概念及应用 映射方法是sa开头的所有方法 如 ...
- Spring Boot & Restful API 构建实战!
作者:liuxiaopeng https://www.cnblogs.com/paddix/p/8215245.html 在现在的开发流程中,为了最大程度实现前后端的分离,通常后端接口只提供数据接口, ...
- Spring相关jar说明
Spring整合使用说明 一.只是使用spring框架 dist\spring.jar lib\jakarta-commons\commons-logging.jar 如果使用到了切面编程(AOP), ...
- Spring的核心api和两种实例化方式
一.spring的核心api Spring有如下的核心api BeanFactory :这是一个工厂,用于生成任意bean.采取延迟加载,第一次getBean时才会初始化Bean Applicatio ...
- 搭建Spring相关框架后,配置信息文件头部出现红色小×错误。
问题描述: 在搭建关于Spring相关框架的时候,在applicationContext.xml配置文件和servlet-mvc.xml配件文件的头部会出现一个红色的小X错误: 错误描述: Refer ...
随机推荐
- CF498B题解
咋黑色啊,这不是看到数据范围就去想 \(O(nT)\) 的做法吗? 然后仔细想想最靠谱的就是 DP. 设 \(dp[n][T]\) 表示听完第 \(n\) 首歌,总共听了 \(T\) 秒. 很明显有 ...
- Go值类型和引用类型+作用域+空白标识符+常量
值类型和引用类型 所有像 int.float.bool 和 string 这些基本类型都属于值类型,使用这些类型的变量直接指向存在内存中的值: 当使用等号 = 将一个变量的值赋值给另一个变量时,如:j ...
- Spring AOP Xml配置过程及解释
目录 Spring AOP(基于xml) 专业术语: 基于xml的声明式AspectJ 具体实践 Spring AOP(基于xml) 目前主流的AOP框架有两个,分别是Spring AOP和Aspec ...
- atoi atof atol
在c语言中提供了把字符串转化为整数的函数,并没有提供把整数转化为字符串的函数 atoi是标准的库函数 itoa不是标准的库函数(在vs可编译,其它系统中未知) atol把一个字符串转化为long类型 ...
- Linux检查服务器是否被入侵
Linux检查服务器是否被入侵 检查root用户是否被纂改 awk -F: '$3==0{print $1}' /etc/passwd awk -F: '$3==0 {print}' /etc/pas ...
- spinlock 设计的初衷,当只有单核时是否还需要锁
自旋锁,的设计初衷是什么,是为了解决什么问题.如果只有一个cpu,并且是单核,那是否还需要用到自旋锁.
- EVM
靶机设置 将靶机导入VirtualBox中,有时候导入VM会出错,扫描不到ip地址. kali:192.168.1.100 kali扫描获得ip地址:192.168.1.107 渗透测试 接着扫描端口 ...
- Python datetime获取当前年月日时分秒
from datetime import datetime now_time = datetime.now() str_time = now_time.strftime("%Y-%m-%d ...
- java LinkedList (详解)
Java 链表(LinkedList) 一.链表简介 1.链表 (Linked List) 是一种常见的基础数据结构,是一种线性表,但是链表不会按线性表的顺序存储数据,而是每个节点里存到下一个节点的地 ...
- leedCode
https://blog.csdn.net/code_yilia/category_9851007.html https://blog.csdn.net/qq_17550379/article/det ...