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 ...
随机推荐
- asp.net文件上传下载
泽优大文件上传产品测试 泽优大文件上传控件up6,基于php开发环境测试. 开发环境:HBuilder 服务器:wamp64 数据库:mysql 可视化数据库编辑工具:Navicat Premium ...
- android-基础编程之开篇
先唠叨两句,机缘巧合现在来做android开发了,之前做后台c的,对这块不是很了解,要慢慢学习,对于framework层的学习感觉需要app开发经验更好点,在完成工作之余积累一些基础知识.既来之则安之 ...
- php获取跳转后的真实链接
网站的跳转链接经常为本站链接加上一些参数来跳转,如何使用php获取跳转后的链接呢? php代码如下: <?php // echo get_redirect_url('http://www.osc ...
- linux下禁用SELinux
http://chenzhou123520.iteye.com/blog/1313582 如何开启或关闭SELinux RedHat的 /etc/sysconfig/selinux 在新版本中的Red ...
- noip第4课资料
- 控制uniFrame显示的一个管理类
控制uniFrame显示的一个管理类 (2016-03-29 06:41:17) 转载▼ 标签: delphi 分类: uniGUI 利用uniGUI Frame的机制来搭建项目,是非常好的实现方式, ...
- [Leet code 2]Two Sum
1 题目 You are given two linked lists representing two non-negative numbers. The digits are stored in ...
- ABP 框架 数据库底层迁移 Mysql 集群
技术交流,请加QQ群:538327407 我的各种github 开源项目和代码:https://github.com/linbin524 背景 笔者 目前架构的IOT 项目是使用abp 框架作为后台, ...
- ContentControl as CC和ContentPresenter as CP的使用
1.CC为文本控件的父类,它继承为control,所以他是控件, 2.CP继承FrameworkElement,所以他是容器,相当于占位符 3.想让控件中能包含子控件就需要用CP,反之用CC就行.(不 ...
- ASP.NET MVC NPOI导入Excel DataTable批量导入到数据库
使用NPOI导入Excel 首先在MVC项目中导入NPOI 查询NPOI安装,排序依据,选择:最高下载量,选择第一个. 在控制器中创建ExcelController 在Index视图中写入代码: @u ...