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 ...
随机推荐
- jmeter从文件中读取参数,并实现循环
1. 通过BeanShell Sampler获取csv的行数 import java.io.BufferedReader;import java.io.FileReader;BufferedReade ...
- Django-安装/分组命名/路由分发
一.安装Django 命令行窗口: pycharm安装: 二.创建Django项目 命令行窗口创建项目: 访问地址: 表示访问成功 注意如果我们在命令行窗口创建的应用需要我们手动的在django的se ...
- Leetcode题目78.子集(回溯-中等)
题目描述: 给定一组不含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集). 说明:解集不能包含重复的子集. 示例: 输入: nums = [1,2,3] 输出: [ [3], [1] ...
- H5-Mui框架——修改mui.confirm样式
问题简述: 使用mui框架默认提示框时,感觉与整体布局不符,因此想要更改其中的样式. 首先,查了一下资料:mui.toast样式风格及位置修改教程 以下是转载过来的文章内容. ============ ...
- Configuring Windows for Certificate Logon
Setting up a Windows Domain ( on AD) Installing Domain Controller Roles,During installing Active Dir ...
- LC 926. Flip String to Monotone Increasing
A string of '0's and '1's is monotone increasing if it consists of some number of '0's (possibly 0), ...
- VBA ListView控件使用实例
功能:ListView控件实现连接数据库实现显示查询数据空能. 图片: 代码: Private Sub CommandButton1_Click() Dim res As String res = T ...
- 终端less命令执行完之后怎样退出
Linux中的less命令主要用来浏览文件内容,与more命令的用法相似,不同于more命令的是,less命令可往回卷动浏览以看过的部分,less 的用法比起 more 更加的有弹性.如果想退出les ...
- Node Newbie Error – NPM Refusing to Install Package as a Dependency of Itself
46 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_ ...
- openstack核心组件--glance镜像(2)
一.glance介绍: Glance是Openstack项目中负责镜像管理的模块,其功能包括虚拟机镜像的查找.注册和检索等. Glance提供Restful API可以查询虚 ...