spring 资源访问
spring 资源访问
Resource resource=null;
//访问网络资源
resource=new UrlResource("file:bool.xml");
//访问类加载路径下的资源
resource=new ClassPathResource("book.xml");
//访问文件系统资源
resource=new FileSystemResource("book.xml");
//访问字节数组资源
String str="";
byte[] fileBytes=str.getBytes();
resource=new ByteArrayResource(fileBytes);
//resource=new ServletContextResource()
//resource=new InputStreamResource()
InputStream inputStream= resource.getInputStream();
boolean exists=resource.exists();
boolean isOpen=resource.isOpen();
String description=resource.getDescription();
File file=resource.getFile();
URL url= resource.getURL(); ApplicationContext ctx=new ClassPathXmlApplicationContext("beans.xml");
resource=ctx.getResource("book.xml"); ctx=new FileSystemXmlApplicationContext("beans.xml");
ctx=new FileSystemXmlApplicationContext("/beans.xml");
//加载相对路径
ctx=new FileSystemXmlApplicationContext("file:beans.xml");
//加载绝对路径
ctx=new FileSystemXmlApplicationContext("file:/beans.xml");
ctx=new FileSystemXmlApplicationContext("classpath:beans.xml");
//加载多个配置文件
ctx=new FileSystemXmlApplicationContext("classpath*:beans.xml");
ctx=new ClassPathXmlApplicationContext("beans*.xml");
ctx=new FileSystemXmlApplicationContext("classpath*:bean*.xml");
配置管理
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource; //修饰一个Java配置类
@Configuration
//导入XML配置
@ImportResource("classpath:/beans.xml")
public class AppConfig {
//修饰一个方法,将该方法的返回值定义成容器中的一个Bean
@Bean
public Person person(){ }
@Bean(name = "stoneAxe")
public Axe stoneAxe(){ }
@Bean(name = "steelAxe")
public Axe steelAxe(){ }
}
spring 资源访问的更多相关文章
- spring资源访问接口和资源加载接口
spring 资源访问接口 JDK提供的资源访问类,如java.net.URL.File等,不能很好地满足各种资源的访问需求,比如缺少从类路径或者Web容器的上下文中获取资源的操作类. 鉴于此,spr ...
- Spring资源访问
资源访问 1.Resource Jdk提供的访问资源的类并不能很好地满足各种底层的资源访问需求, 比如缺少从类路径或者web容器的上下文中获取资源的操作类. 鉴于此, Spring设计了一个Resou ...
- 攻城狮在路上(贰) Spring(三)--- Spring 资源访问利器Resource接口
Spring为了更好的满足各种底层资源的访问需求.设计了一个Resource接口,提供了更强的访问底层资源的能力.Spring框架使用Resource装载各种资源,包括配置文件资源.国际化属性文件资源 ...
- Spring资源访问接口Resource
该接口拥有对不同资源类型的实现类 boolean exists() 资源是否存在 boolean isOpen() 资源是否打开 URL getURL() 如果底层资源可以表示成URL,则该方法返回对 ...
- 05.Spring 资源加载 - Resource
基本概念 Spring 把所有能记录信息的载体,如各种类型的文件.二进制流等都称为资源. 对 Spring 开发者来说,最常用的资源就是 Spring 配置文件(通常是一份 XML 格式的文件). S ...
- Spring源码分析——资源访问利器Resource之实现类分析
今天来分析Spring的资源接口Resource的各个实现类.关于它的接口和抽象类,参见上一篇博文——Spring源码分析——资源访问利器Resource之接口和抽象类分析 一.文件系统资源 File ...
- spring mvc官网下最新jar搭建框架-静态资源访问处理-注解-自动扫描
1.从官网下载spring相关jar http://spring.io/projects 点击SPRING FRAMEWORK
- Spring MVC 使用介绍(十一)—— 跨域与静态资源访问
一.跨域 服务端须在响应中添加相应响应头,从而允许跨域,具体可通过 public class CorsFilter extends OncePerRequestFilter { @Override p ...
- Spring Boot 静态资源访问原理解析
一.前言 springboot配置静态资源方式是多种多样,接下来我会介绍其中几种方式,并解析一下其中的原理. 二.使用properties属性进行配置 应该说 spring.mvc.static-pa ...
随机推荐
- 微信小程序 js结构
// pages/index/index.js Page({ /** * 页面的初始数据 */ data: { }, /** * 生命周期函数--监听页面加载 */ onLoad: function ...
- Kindeditor图片粘贴上传(chrome)
kindeditor4.1.x版本已支持图片批量上传,不过传统的选文件上传的方式依然效率低下. 很多时候,编辑人员可能需要将一个文档中图片上传到网上,那么,按照传统的上传方法,他必须先将图片另存为到本 ...
- 笔记 Bioinformatics Algorithms Chapter7
一.Lloyd算法 算法1 Lloyd Algorithm k_mean clustering * Centers to Clusters: After centers have been selec ...
- SQL Server 2008 表分区的含义
https://www.cnblogs.com/knowledgesea/p/3696912.html 继续看这个文档 http://www.360doc.com/content/16/0104/11 ...
- Android-Kotlin-递归与尾递归
递归: 阶乘计算: /** * 阶乘: * 1的阶乘是1,因为1往下走一个楼梯 就是0了 * 2的阶乘是 2*1 * 3的继承是 3*2*1 * 4的继承是 4*3*2*1 * 5的阶乘是 5*4*2 ...
- java 堆排序的实现
堆就是一个完全二叉树,堆要求是指 该节点大于它的两个子节点.而两个字节点大小不一定. 堆排序的最坏时间复杂度为nlog(n),平均也为nlog(n),占用空间为o(1),是一种比较排序算法. 堆排序也 ...
- Partition--使用分区切换来增加修改列的自增属性
使用分区来将非自增表改为自增表 ------------------------------------------------- --创建测试表TestTable001和TestTable002 C ...
- 背水一战 Windows 10 (40) - 控件(导航类): AppBar, CommandBar
[源码下载] 背水一战 Windows 10 (40) - 控件(导航类): AppBar, CommandBar 作者:webabcd 介绍背水一战 Windows 10 之 控件(导航类) App ...
- 2019年微服务实践第一课,网易&谐云&蘑菇街&奥思技术大咖深度分享
微服务的概念最早由Martin Fowler与James Lewis于2014年共同提出,核心思想是围绕业务能力组织服务,各个微服务可被独立部署,服务间是松耦合的关系,以及数据和治理的去中心化管理.微 ...
- Android 使用 NYTimes Stores 缓存 network request
NYTimes Stores 是一个缓存库,在 2017年的 AndroidMakers 大会上被介绍过. https://github.com/NYTimes/Store 实现一个 Disk Cac ...