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 ...
随机推荐
- 常见的Socket网络异常场景分析
原创:打码日记(微信公众号ID:codelogs),欢迎分享,转载请保留出处. 简介 在目前微服务的背景下,网络异常越来越常见了,而有一些网络异常非常模糊,理解什么情况下会导致什么异常,还是有一定难度 ...
- ArcGIS进行容积率计算
空间分析--题目2 容积率(Plot Ratio/Floor Area Ratio/Volume Fraction)又称建筑面积毛密度,是指一个小区的地上总建筑面积与用地面积的比率.对于开发商来说,容 ...
- Linux 查询文件内容重复数 uniq、sort命令
前提:uniq只能查询数据相邻的重复次数,而sort可以查询乱序的重复次数. 原谅我,以下内容都是复制菜鸟驿站的!!! Linux uniq 命令用于检查及删除文本文件中重复出现的行列,一般与 sor ...
- 6月6日 python复习 面向对象
1.面向对象编程 1.面向过程编程核心是"过程"二字,过程指的是解决问题的步骤,即先干什么再干什么基于该思想编写程序就好比在编写一条流水线,是一种机械式的思维方式 优点:复杂的问题 ...
- Presidential-01
环境搭建 官网地址:https://www.vulnhub.com/entry/presidential-1,500/ 靶机下载地址: https://download.vulnhub.com/pre ...
- MVC 生成安全验证码(例:用于登陆验证) 方法2
MVC前台页面中,重新获取图片验证码的第二种方式:(前端页面代码如下,后台页面请参考上一篇文章) ---------html <td> <img id="imgValida ...
- springboot的核心配置文件
一.springboot主要配置文件种类 1.bootstrap (.yml或.properties) 2.application(.yml或.properties) 二.bootstrap与appl ...
- Dubbo 服务降级,失败重试怎么做?
可以通过 dubbo:reference 中设置 mock="return null".mock 的值也可以修 改为 true,然后再跟接口同一个路径下实现一个 Mock 类,命名 ...
- int 和 Integer 有什么区别?
Java 是一个近乎纯洁的面向对象编程语言,但是为了编程的方便还是引入了基本 数据类型,但是为了能够将这些基本数据类型当成对象操作,Java 为每一个基本 数据类型都引入了对应的包装类型(wrappe ...
- Java中如何声明方法?JavaScript中如何声明函数?
public void method(){ } //实例方法 Function Declaration 可以定义命名的函数变量,而无需给变量赋值.Function Declaration 是一种独立的 ...