Jboss: Using reverse path on top path: /xxx
环境
- jboss 5.2
原因
加载资源的协议错误。一般在加载文件的时候,URL 都是以 file: 开头,但是在 jboss 上时,由于其虚拟化了路径,导致协议不一致,并且找不到外部的配置文件。
分析
通过将项目部署到 jboss 服务器上,打印日志查看其获得的 URL 如下:
vfsmemory://a653x1c-xfikka-k3i9k2ku-1-k3i9kk9n-2s/
该目录结构已被虚拟化,不能够获得服务器中的目录结构。
外部配置
优化后的外部配置,使用 tomcat 服务器是可以了,由于 jboss 比较特殊,不能够获取服务器真实的相对路径。可以使用 getClass().getResource("") ,即使用当前类的相对路径来解决。
// classpath 目录,上级目录的个数和当前类的类名层级相对应。
String path = PathDemo.class.getResource("../../").getPath();
Resource resource = new FileSystemResource(path + EXTERNAL_CONFIG_FILE);
try {
logger.info("外部配置目录为:{}", resource.getFile().getCanonicalPath());
if (!resource.exists()) {
logger.info("外部配置不存在。");
return;
}
ResourcePropertySource source = new ResourcePropertySource(new EncodedResource(resource, "UTF-8"));
// 外部化配置的优先级最高
beanFactory.getBean(StandardEnvironment.class).getPropertySources().addFirst(source);
} catch (IOException e) {
logger.error("加载外部化配置出错。", e);
}
拓展
如果使用该种方法,发现目录结构完全正确,但始终不能找到配置文件,
则可以参考这里
附录
获取 jboss 目录
logger.info("class / :{}", getClass().getResource("/"));
logger.info("class :{}", getClass().getResource(""));
logger.info("file class / :{}", getClass().getResource("/").getFile());
logger.info("file class :{}", getClass().getResource("").getFile());
logger.info("path class / :{}", getClass().getResource("/").getPath());
logger.info("path class :{}", getClass().getResource("").getPath());
logger.info("loader / :{}", getClass().getClassLoader().getResource("/"));
logger.info("loader:{}", getClass().getClassLoader().getResource(""));
logger.info("file loader / :{}", getClass().getClassLoader().getResource("/").getFile());
logger.info("file loader:{}", getClass().getClassLoader().getResource("").getFile());
logger.info("path loader / :{}", getClass().getClassLoader().getResource("/").getPath());
logger.info("path loader:{}", getClass().getClassLoader().getResource("").getPath());
logger.info("thread /: {}", threadLoader.getResource("/"));
logger.info("thread : {}", threadLoader.getResource(""));
logger.info("file thread /: {}", threadLoader.getResource("/").getFile());
logger.info("file thread : {}", threadLoader.getResource("").getFile());
logger.info("path thread /: {}", threadLoader.getResource("/").getPath());
logger.info("path thread : {}", threadLoader.getResource("").getPath());
对应输出结果
class / :vfsmemory://a653x1c-xfikka-k3i9k2ku-1-k3i9kk9n-2s/
class :vfszip:/DATA/app/jboss/appdeploy/demo.war/WEB-INF/classes/jiangbo/demo/
file class / :/
file class :/DATA/app/jboss/appdeploy/demo.war/WEB-INF/classes/jiangbo/demo/
path class / :/
path class :/DATA/app/jboss/appdeploy/demo.war/WEB-INF/classes/jiangbo/demo/
loader / :vfsmemory://a653x1c-xfikka-k3i9k2ku-1-k3i9kk9n-2s/
loader:vfsmemory://a653x1c-xfikka-k3i9k2ku-1-k3i9kk9n-2s/
file loader / :/
file loader:/
path loader / :/
path loader:/
thread /: vfsmemory://a653x1c-xfikka-k3i9k2ku-1-k3i9kk9n-2s/
thread : vfsmemory://a653x1c-xfikka-k3i9k2ku-1-k3i9kk9n-2s/
file thread /: /
file thread : /
path thread /: /
path thread : /
Jboss: Using reverse path on top path: /xxx的更多相关文章
- sys.path和os.path
sys.path和os.path1.sys.path是python搜索模块的路径集合,是个list:os.path是os的一个模块,是操作文件和目录的模块 2.sys.path和PYTHONPATH首 ...
- linux环境下安装jdk(本文示例是jdk1.6.0_export JAVA_HOME=/usr/java/jdk1.6.0_45 export PATH=$JAVA_HOME/bin:$PATH export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar45)
第一步:创建一个文件夹安装jdk(虽说地址一般自定义,但是为了方便查找请按照笔者建议目录 ):/usr/java 将jdk-6u45-linux-x64.bin文件放到 /usr/java 文件夹 ...
- python中os.path 与sys.path
看别人写的代码,会发现两个和路径设置有关的模块 os 和sys.我对这两个模块也不是特别了解.只是记录一下自己看到的,学到的. python 中我们会使用这两个模块和文件路径, 创建文件 之类的 操作 ...
- node模块之path——path.join和path.resolve的区别
1.path.join([...paths]) path.join() 方法使用平台特定的分隔符把全部给定的 path 片段连接到一起,并规范化生成的路径. 长度为零的 path 片段会被忽略. 如果 ...
- sys.path.insert(0,"/path") 的用法
可以选择用sys.path.insert(0,‘/path’),这样新添加的目录会优先于其他目录被import检查
- Path Creation and Path Painting
[Path Creation and Path Painting] Path creation and path painting are separate tasks. First you crea ...
- path.join()与path.resolve()区别
1.path.resolve([...paths]) path.resolve() 方法会把一个路径或路径片段的序列解析为一个绝对路径. 给定的路径的序列是从右往左被处理的,后面每个 path 被依次 ...
- difference in physical path, root path, virutal path, relative virtual path, application path and aboslute path?
http://stackoverflow.com/questions/13869817/difference-in-physical-path-root-path-virutal-path-relat ...
- golang程序编译时提示“package runtime: unrecognized import path "runtime" (import path does not begin with hostname)”
在编译golang的工程时提示错误的, 提示的错误信息如下: package bytes: unrecognized import path "bytes" (import pat ...
随机推荐
- Intel Code Challenge Final Round D. Dense Subsequence 二分思想
D. Dense Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- HFUUOJ1024 动态开点线段树+标记永久化
题意 分析 动态加点线段树,标记永久化好写常数小 Code #include<bits/stdc++.h> #define fi first #define se second #defi ...
- codeforces#1183F. Topforces Strikes Back(数论)
题目链接: http://codeforces.com/contest/1183/problem/F 题意: 给出n个数,找出最多三个互不整除的数,取最大的和 数据范围: $1 \le n \le 2 ...
- lyc——2019.10.31
10:判决素数个数 总时间限制: 1000ms 内存限制: 65536kB 描述 输入两个整数X和Y,输出两者之间的素数个数(包括X和Y). 输入 两个整数X和Y(1 <= X,Y <= ...
- 2017 ZSTU寒假排位赛 #8
题目链接:https://vjudge.net/contest/149845#overview. A题,水题. B题,给出 p个 第一个人的区间 和 q个第二个人的区间,问[l,r]中有多少个整数满足 ...
- MongoDB系列二:MongoDB安装过程
一.MongoDB安装,以Linux系统安装为例:(下载:www.mongodb.org 注意使用stable版本) 1.下载最新版本的MongoDB安装包,wget http://fastdl.mo ...
- 使用arcpy.mapping 更新和修复数据源
来自:https://blog.csdn.net/gisinfo/article/details/6675390 在许多情况下,您都可能需要修复数据源或重定向数据源至其他位置.然而,如果是在每个相关的 ...
- 1.springboot启动流程
SpringBoot版本:2.1.2.RELEASE 1.maven <parent> <groupId>org.springframework.boot</groupI ...
- JavaScript如何封装插件
什么是封装呢? 我的理解就是 把一个功能单独做成一个组件,就像做饺子,以前做饺子必须自己先用面粉做饺子皮,再做饺子馅,然后再手工包饺子,但是现在人们发明了自动包饺子机器,虽然机器里面的每一步骤和你自己 ...
- 重画GoogleClusterTrace数据
由于项目计划书写作需要,重画了Qi Zhang, Mohamed Faten Zhani, Raouf Boutaba, Joseph L. Hellerstein, Dynamic Heteroge ...