FileSystemXmlApplicationContext方法的绝对路径问题
- public AgentServer(Socket c,String confDir) {
this.client = c;
ApplicationContext ac = new FileSystemXmlApplicationContext(confDir);
this.atsMgr = (AtsMgr) ac.getBean("atsMgr");
}
用FileSystemXmlApplicationContext方法准备去容器中取bean,在window环境下没有问题,但是放到Jenkins上面发现总是报错,说文件找不到:
- /home/docker/.jenkins/jobs/ats/workspace/target/test-classes/utap-ats.xml
- org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from file [/home/docker/.jenkins/jobs/ats/workspace/home/docker/.jenkins/jobs/ats/workspace/target/test-classes/utap-ats.xml]; nested exception is java.io.FileNotFoundException: home/docker/.jenkins/jobs/ats/workspace/target/test-classes/utap-ats.xml (No such file or directory)
- at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:343)
- at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
- at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
- at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216)
- at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187)
- at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:251)
- at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
- at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
- at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
- at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
- at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:452)
- at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
- at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84)
- at com.newland.sri.utap.ats.AgentServer.<init>(AgentServer.java:31)
- at com.newland.sri.utap.ats.AtsTest$T1.run(AtsTest.java:57)
- at java.lang.Thread.run(Thread.java:745)
- Caused by: java.io.FileNotFoundException: home/docker/.jenkins/jobs/ats/workspace/target/test-classes/utap-ats.xml (No such file or directory)
- at java.io.FileInputStream.open0(Native Method)
- at java.io.FileInputStream.open(FileInputStream.java:195)
- at java.io.FileInputStream.<init>(FileInputStream.java:138)
- at org.springframework.core.io.FileSystemResource.getInputStream(FileSystemResource.java:115)
- at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:329)
- ... 15 more
查看源码发现,FileSystemXmlApplicationContext方法对路径进行了处理:
- protected Resource getResourceByPath(String path) {
- if(path != null && path.startsWith("/")) {
- path = path.substring(1);
- }
- return new FileSystemResource(path);
- }
- }
用绝对路径时,第一个斜杠会被去掉(也是不知道为什么,我勒个去),所以,给在代码前再加个斜杠解决问题,代码通过:
- public AgentServer(Socket c,String confDir) {
- this.client = c;
- ApplicationContext ac = new FileSystemXmlApplicationContext("/" + confDir);
- this.atsMgr = (AtsMgr) ac.getBean("atsMgr");
- }
FileSystemXmlApplicationContext方法的绝对路径问题的更多相关文章
- 使用Class.getResource和ClassLoader.getResource方法获取文件路径
自从转投Java阵营后,一直发下Java程序的路径读取异常麻烦,因此查阅了比较多的版本内容,整合了一份自己的学习笔记.主要使用Class及通过ClassLoader来动态获取文件路径. 查阅链接如下: ...
- 【转载】使用Class.getResource和ClassLoader.getResource方法获取文件路径
自从转投Java阵营后,一直发下Java程序的路径读取异常麻烦,因此查阅了比较多的版本内容,整合了一份自己的学习笔记.主要使用Class及通过ClassLoader来动态获取文件路径. 查阅链接如下: ...
- dbutils中实现数据的增删改查的方法,反射常用的方法,绝对路径的写法(杂记)
jsp的三个指令为:page,include,taglib... 建立一个jsp文件,建立起绝对路径,使用时,其他jsp文件导入即可 导入方法:<%@ include file="/c ...
- nodejs路径处理方法和绝对路径
1. 路径处理方法 __dirname 表示当前文件所在的目录的绝对路径__filename 表示当前文件的绝对路径module.filename ==== __filename 等价process. ...
- phpmyadmin后台4种拿shell方法 && php爆路径大法
php后台拿shell要知道php的路径,文章下面将讲诉爆php路径的方法!!! 方法一: CREATE TABLE `mysql`.`xss` (`xss1` TEXT NOT NULL ); IN ...
- 封装的方法--读取任何路径下的properties文件中的值
概述:我们在做项目时,经常需要从某个properties文件中读取properties文件中的值.现在我封装了一下方法,直接读取配置文件中的值. 代码如下所示: /** * Created by qi ...
- linux开机启动服务和chkconfig使用方法(自定义服务路径启动)
服务概述在linux操作系统下,经常需要创建一些服务,这些服务被做成shell脚本,这些服务需要在系统启动的时候自动启动,关闭的时候自动关闭.将 需要自动启动的脚本/etc/rc.d/init.d目录 ...
- swift两种获取相册资源PHAsset的路径的方法(绝对路径)
方法中使用到的phasset就是我们取到的PHAsset对象 方法一: let options = PHVideoRequestOptions() options.version = PHVideoR ...
- System.getProperty方法中输出路径的方法
package codegenerator;/** *@author Eilen *@date 2017年9月27日---下午3:15:09 *@描述: *@answer */public class ...
随机推荐
- 【Python@Thread】threading模块
theading模块的Thread类 属性: name 线程名 ident 线程标识符 daemon 布尔值,标示是否为守护线程 方法: __init__(target=None, name=Non ...
- 用户id有则更新,无则添加 使用replace into (代替 insert into)
app登录成功后,调用后台,更新channel_id public function set_pushchannel($device,$channelid,$iv='' ) $sql = " ...
- LeetCode OJ 123. Best Time to Buy and Sell Stock III
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- 使用InternetReadFile时要注意读取完整数据
使用这个api读取数据后,即使数据不完整,该函数不会报任何错,GetLastError也显示操作成功.使用时要注意通过其参数判断是否读取完毕 void InternetReadFileEx(HINTE ...
- iOS之文件解析
JSON JSON – OC 转换对照表 JSON OC {} NSDictonary [] NSArray "" NSString 数字 10,10.5 NSNumber NSJ ...
- ejabberd聊天室离线消息
首先,xmpp服务器是基于ejabberd.离线消息模块是mod_interact,原地址地址:https://github.com /adamvduke/mod_interact: 修改后实现群聊离 ...
- CSS居中方法
css居中方法非常多,根据工作的实际情况采用恰当方法,可取到事半功倍的效果. 就常见的一些居中方法整理如下: 代码如下: <div class="con"> <d ...
- js iframe跨域访问
1.什么是跨域? 2.前台解决跨域几种方法 2.1 动态创建script 2.2 使用document.domain 2.3使用HTML5新属性postMessage 2.4 利用iframe和loc ...
- poll机制分析[转]
所有的系统调用,基于都可以在它的名字前加上"sys_"前缀,这就是它在内核中对应的函数.比如系统调用open.read.write.poll,与之对应的内核函数为:sys_open ...
- Jersey客户端API调用REST风格的Web服务
Jersey 客户端 API 基础 jersey-1.14.jar 密码: cxug 要开始使用 Jersey 客户端 API,你首先需要创建一个 com.sun.jersey .api.client ...