struts2对properties资源的处理
struts2对properties资源的处理
做了一些功能增强
包括:
可以读取项的描述
可以读取项所在的行号,文件路径等
实现方式
继承了java的java.util.Properties实现了一个类LocatableProperties完成此事。
LocatableProperties对外公布了load api完成properties文件的读取,但内部逻辑还是靠其自定义的PropertiesReader完成的。
PropertiesReader继承自java的java.io.LineNumberReader,主要利用其原有的构造方法,readLine等方法。
LocatableProperties在构造时或者构造完成后,需要向其传递Location对象(包括文件描述,文件路径等信息),否则LocatableProperties是没法知道文件文件位置的。
z
@Test
public void testLocatableProperties001()
{
try
{
String propertiesPath = "/cn/chenxiaguang/demo/sss/xwork2/util/location/testConfigData.properties";
Location loc = new LocationImpl("测试配置文件", this.getClass().getResource(propertiesPath).toString());
LocatableProperties locatableProperties = new LocatableProperties(loc);
locatableProperties.load(this.getClass().getResourceAsStream(propertiesPath));
System.out.println(locatableProperties.getPropertyLocation("a"));
System.out.println(locatableProperties.getPropertyLocation("b"));
}
catch (IOException e)
{
e.printStackTrace();
}
}
testConfigData.properties
#test a
a=1 #test b
b=2
但是在打印 时并不会打印出properties文件的描述信息。
打印结果信息如下:
#test a
- file:/Users/simon/600.self/05.code/04.java/10.struts2-src-study/struts2-src-study/WebContent/WEB-INF/classes/cn/chenxiaguang/demo/sss/xwork2/util/location/testConfigData.properties:3:0
#test b
- file:/Users/simon/600.self/05.code/04.java/10.struts2-src-study/struts2-src-study/WebContent/WEB-INF/classes/cn/chenxiaguang/demo/sss/xwork2/util/location/testConfigData.properties:6:0
当然 struts2还对xml文件等做了信息定位,主要使用sax api的特性完成。
struts2对properties资源的处理的更多相关文章
- java中根据key获取resource下properties资源文件中对应的参数
properties资源文件是放在resource目录下的: 新建工具类: package com.demo.utils; import java.io.InputStream; import jav ...
- Spring3.x 获取properties资源文件的值
Spring3.x 获取properties资源文件的值有两种方式: 第一种:使用<context:property-placeholder />标签 <context:prop ...
- 读取web工程中.properties资源文件的模板代码
读取web工程中.properties资源文件的模板代码 // 读取web工程中.properties资源文件的模板代码 private void test2() throws IOException ...
- 在服务端中,读取properties资源文件中的数据
1.获取到资源的路径 2.读取数据 //properties文件对象 Properties properties = new Properties(); //通过HttpServletRequest ...
- Struts2配置国际化资源
1. 国际化的目标 1). 如何配置国际化资源文件 I. Action 范围资源文件: 在Action类文件所在的路径建立名为 ActionName_language_country.properti ...
- 不停服务,动态加载properties资源文件
系统运行过程中,我们用注解@Value("${****}")可以获取资源文件中的内 容,获取的内容会被存储在spring缓存中,因此如果我们修改了资源文件,要 想读取到修改后的内容 ...
- 装载Properties资源文件的项目中使用
ssm项目中打算将发短信的每小时每天的限定变成可配置的.于是将配置信息写在资源文件中,现在有两种方式加载资源文件,一个是使用spring注入方式,@Value注解注入,当然,前面需要在项目中装载.第二 ...
- maven 打包时动态替换properties资源文件中的配置值
pom build节点下面添加resource配置: <resources> <resource> <directory>src/main/resources/&l ...
- Spring读取properties资源文件
我们知道可以通过读取资源文件流后加载到Properties对象,再使用该对象方法来获取资源文件.现在介绍下利用Spring内置对象来读取资源文件. 系统启动时加载资源文件链路:web.xml --&g ...
随机推荐
- swift基础-2
一.基本运算符 let a = 5 var b = 10 b = a if a = b{ swift 中赋值运算符,并不将自身作为一个值进行返回,所以编译不合法,帮开发者避免错误,很人性化的语言 } ...
- css 居中问题总结
html代码: <div class="box"> <div class="box-item"> 文字 </div> < ...
- 编译错误you should not run configure as root (set FORCE_UNSAFE_CONFIGURE=1 in environment to bypass this check)
解决方法: export FORCE_UNSAFE_CONFIGURE=1
- Python2和Python3语法区别
1.使用for循环进行换行 python 2.x, print 不换行>>> print x, python 3.x print 不换行>>> print(x, e ...
- 连接惠普打印机(通过WIFI)
第一步 找到打印机型号 第二步 到惠普官方网站下载对应驱动 第三步 安装驱动 第四步 安装驱动后选择WIFI连接(IP在打印机显示屏幕上显示,如果输入打印机屏幕IP连接失败:需要获取打印机真正的IP地 ...
- 2018.4.16 Java多线程实现龟兔赛跑
龟兔赛跑(通过多线程来实现 里面的具体方法) TT.java package com.lanqiao.demo3; /** * 乌龟 * @author Administrator * */ publ ...
- 2018.4.11 Java为何用xml做配置文件? 理由如下
在Java世界里xml配置文件几乎是首选,xml有什么好的特性呢? 第一:xml能存储小量数据,仅仅是存储数据. 第二:xml可以跨平台,主流各种平台都对xml有支持, 真正的跨平台, 第三:xml读 ...
- Spring boot 集成Kafka
搭建Kafka集群,参考: https://www.cnblogs.com/jonban/p/kafka.html 源码示例如下: 1.新建 Maven 项目 kafka 2.pom.xml < ...
- iOS应用架构谈part3 网络层设计方案
前言 网络层在一个App中也是一个不可缺少的部分,工程师们在网络层能够发挥的空间也比较大.另外,苹果对网络请求部分已经做了很好的封装,业界的AFNetworking也被广泛使用.其它的ASIHttpR ...
- LLDB详解
LLDB的Xcode默认的调试器,它与LLVM编译器一起,带给我们更丰富的流程控制和数据检测的调试功能.平时用Xcode运行程序,实际走的都是LLDB.熟练使用LLDB,可以让你debug事半功倍 L ...