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 的默认配置文件 ,加 ...
随机推荐
- maven系列小技巧之Top3 MVQ(most valuable question)
首先声明,文章系个人原创 ,欢迎转载,转载请注明出处. 对于maven,有大神曾说过:如果你爱他,就请让他用Maven,因为那里是天堂,如果你恨他,就请让他用Maven,因为那里是地狱.尤其是mave ...
- zabbix java api
zabbix java api zabbix官方的api文档地址:https://www.zabbix.com/documentation/3.0/manual/api Zabbix功能 概观 Zab ...
- Linux - 简明Shell编程05 - 条件语句(Case)
脚本地址 https://github.com/anliven/L-Shell/tree/master/Shell-Basics 示例脚本及注释 #!/bin/bash var=$1 # 将脚本的第一 ...
- CSS学习笔记!
一.关于图像RGB值和像素值的确定! 腾讯QQ截图软件Ctrl+Alt+A进入截图界面,鼠标变成彩色,便会拾取鼠标当前颜色,再按住Ctrl切换到十六进制格式#******.图像的像素值也在截取框内显示 ...
- WebService核心文件【web-config.wsdd】调用操作
WebService核心文件[server-config.wsdd]详解及调用示例 作者:玛莎拉蒂-小贱人 一.准备工作 导入需要的jar包: 二.配置web.xml 在web工程的web.xml中添 ...
- js基础提高(二)
JavaScript基础提高(二) 上篇写的是JavaScript的历史.基本的数据类型和基本的语法进填的话讲的就深入一些了. js的函数 1.js函数定义的方式 (1)普通方式 语法:functio ...
- 从"汉诺塔"经典递归到JS递归函数
前言 参考<JavaScript语言精粹> 递归是一种强大的编程技术,他把一个问题分解为一组相似的子问题,每一问题都用一个寻常解去解决.递归函数就是会直接或者间接调用自身的一种函数,一般来 ...
- GCC和G++区别
原文:http://www.cnblogs.com/samewang/p/4774180.html 看的Linux公社的一篇文章,觉得不错,内容复制过来了. 其实在这之前,我一直以为gcc和g++是一 ...
- JavaScript实现省市联动
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...
- 深度剖析Redis持久化
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt118 Redis是一种面向"key-value"类型数据 ...