spring的配置文件和加载
①:创建applicationContext.xml配置文件放在src下
//applicationContext.xml代码
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<bean id="student" class="entity.Student" scope="prototype"></bean>
</beans>
②:导入ioc jar包并创建对应的java类(entity.Studen);
commons-logging.jar
spring-beans-版本号.RELEASE.jar
spring-context-版本号.RELEASE.jar
spring-core-版本号.RELEASE.jar
spring-expression-版本号.RELEASE.jar
③:加载配置文件创建实例
String str="applicationContext.xml";
ApplicationContext ac=
new ClassPathXmlApplicationContext(str);
Student s =ac.getBean("student",Student.class);
spring的配置文件和加载的更多相关文章
- Spring Cloud配置文件加载优先级简述
Spring Cloud中配置文件的加载机制与其它的Spring Boot应用存在不一样的地方:如它引入了bootstrap.properties的配置文件,同时也支持从配置中心中加载配置文件等:本文 ...
- Spring之配置文件加载方式
spring在org.springframework.core.io包中提供了多种配置文件加载方式.无论是XML.URL还是文件,都有很好的支持.比如基于URL的UrlResource.基于输入流的I ...
- Spring Web 配置文件加载路径问题
Spring: 定位 载入 注册 我们常用的加载context文件的方法有如下三个: 1.FileSystemXmlApplicationContext 这个方法是从文件绝对路径加载配置文 ...
- Spring boot 配置文件 加载顺序
springboot 启动会扫描以下位置的application.properties或者application.yml文件作为Spring boot的默认配置文件 –file:./config/ – ...
- 【串线篇】spring boot配置文件加载位置
springboot 启动会扫描以下位置的application.properties或者application.yml文件作为Spring boot的默认配置文件 (1)–file:./config/ ...
- Spring Boot配置文件加载顺序
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 前言 一.通过spring.config.location改变配置文件的位置 二.外部配置加载顺序 1.使用命令行参数指定加 ...
- Spring Bean注册和加载
Spring解密 - XML解析 与 Bean注册 Spring解密 - 默认标签的解析 Spring解密 - 自定义标签与解析 Spring解密 - Bean的加载流程
- spring之:XmlWebApplicationContext作为Spring Web应用的IoC容器,实例化和加载Bean的过程
它既是 DispatcherServlet 的 (WebApplicationContext)默认策略,又是 ContextLoaderListener 创建 root WebApplicationC ...
- Spring boot 配置文件默认放置位置,和加载优先级
一 .默认配置文件目录 spring boot 启动会扫描以下位置的application.properties 或者application.yml文件作为spring boot 的默认配置文件 ,加 ...
随机推荐
- Python 装饰器总结
装饰器总结 前提 使用装饰器的前提在于Python提供的特性: 函数即对象,可以进行传递: 函数可以被定义在另外一个函数中: 可以通过一个例子来了解: def get_animal(name='dog ...
- 案例:数据库open时报错ORA-1172,ORA-1151 处理
环境:OEL 5.7 + Oracle 10.2.0.5 Clusterware + Oracle 10.2.0.5 RAC 故障:数据库open时报错ORA-1172,ORA-1151 1.故障详细 ...
- Jsp分页的简单制作
Jsp分页的简单制作 运行环境:jsp+tomcat+eclipse 技术:servlet+jsp+mysql 分页技术还区分两个:假分页和真分页 假分页:一次性从数据库读出表的所有数据一次性的返回给 ...
- python——序列 & 集合 & 映射
列表 & 元组 & 字典 & 集合 序列 序列: 每个元素可以是任何类型(也可以是序列),每个元素被分配一个序号(从0开始)(序号,也叫索引,表示元素的位置) Python中的 ...
- 切换Ubuntu系统python默认版本的方法
另附切换系统python默认版本的方法: 先使用命令: update-alternatives --list python 查看python命令的各种可能结果, 例如我的结果: /usr/bin/py ...
- 截取TableView生成图片
先看一下实例效果: 如果所示,这是一个在APP中截图,并调起微信客户端,发送给好友的例子,图片就是一个tableView的截图. 先实现一个小例子,如果tableVIew里面的内容,没有超过当前屏幕显 ...
- SQL实现 模糊查询(转)
在进行数据库查询时,有完整查询和模糊查询之分. 一般模糊查询语句如下: SELECT 字段 FROM 表 WHERE 某字段 Like 条件 其中关于条件,SQL提供了四种匹配模式: 1,% :表示任 ...
- 2017多校第10场 HDU 6180 Schedule 贪心,multiset
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6180 题意:给了一些任务的开始时间和终止时间,现在让我们安排k台及机器,让这些任务在k太机器上最小,并 ...
- 优秀的PE工具收藏
优秀的PE工具收藏... ----------------------- ------------------------------------------<排名不分先后..自己喜欢的就是最好 ...
- Redis持久化总结
Redis持久化总结 因为Redis是内存型数据库,所以为了防止因为系统崩溃等原因导致数据丢失的问题,Redis提供了两种不同的持久化方法来将数据存储在硬盘里面,一种方法是快照(RDB),它可以将存在 ...