1. public AgentServer(Socket c,String confDir) {
    this.client = c;
    ApplicationContext ac = new FileSystemXmlApplicationContext(confDir);
    this.atsMgr = (AtsMgr) ac.getBean("atsMgr");
    }

用FileSystemXmlApplicationContext方法准备去容器中取bean,在window环境下没有问题,但是放到Jenkins上面发现总是报错,说文件找不到:

  1. /home/docker/.jenkins/jobs/ats/workspace/target/test-classes/utap-ats.xml
  2. 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)
  3. at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:343)
  4. at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
  5. at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
  6. at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:216)
  7. at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:187)
  8. at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:251)
  9. at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
  10. at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
  11. at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:129)
  12. at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
  13. at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:452)
  14. at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
  15. at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84)
  16. at com.newland.sri.utap.ats.AgentServer.<init>(AgentServer.java:31)
  17. at com.newland.sri.utap.ats.AtsTest$T1.run(AtsTest.java:57)
  18. at java.lang.Thread.run(Thread.java:745)
  19. Caused by: java.io.FileNotFoundException: home/docker/.jenkins/jobs/ats/workspace/target/test-classes/utap-ats.xml (No such file or directory)
  20. at java.io.FileInputStream.open0(Native Method)
  21. at java.io.FileInputStream.open(FileInputStream.java:195)
  22. at java.io.FileInputStream.<init>(FileInputStream.java:138)
  23. at org.springframework.core.io.FileSystemResource.getInputStream(FileSystemResource.java:115)
  24. at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:329)
  25. ... 15 more

  查看源码发现,FileSystemXmlApplicationContext方法对路径进行了处理:

  1. protected Resource getResourceByPath(String path) {
  2. if(path != null && path.startsWith("/")) {
  3. path = path.substring(1);
  4. }
  5.  
  6. return new FileSystemResource(path);
  7. }
  8. }

  用绝对路径时,第一个斜杠会被去掉(也是不知道为什么,我勒个去),所以,给在代码前再加个斜杠解决问题,代码通过:

  1. public AgentServer(Socket c,String confDir) {
  2. this.client = c;
  3. ApplicationContext ac = new FileSystemXmlApplicationContext("/" + confDir);
  4. this.atsMgr = (AtsMgr) ac.getBean("atsMgr");
  5. }

FileSystemXmlApplicationContext方法的绝对路径问题的更多相关文章

  1. 使用Class.getResource和ClassLoader.getResource方法获取文件路径

    自从转投Java阵营后,一直发下Java程序的路径读取异常麻烦,因此查阅了比较多的版本内容,整合了一份自己的学习笔记.主要使用Class及通过ClassLoader来动态获取文件路径. 查阅链接如下: ...

  2. 【转载】使用Class.getResource和ClassLoader.getResource方法获取文件路径

    自从转投Java阵营后,一直发下Java程序的路径读取异常麻烦,因此查阅了比较多的版本内容,整合了一份自己的学习笔记.主要使用Class及通过ClassLoader来动态获取文件路径. 查阅链接如下: ...

  3. dbutils中实现数据的增删改查的方法,反射常用的方法,绝对路径的写法(杂记)

    jsp的三个指令为:page,include,taglib... 建立一个jsp文件,建立起绝对路径,使用时,其他jsp文件导入即可 导入方法:<%@ include file="/c ...

  4. nodejs路径处理方法和绝对路径

    1. 路径处理方法 __dirname 表示当前文件所在的目录的绝对路径__filename 表示当前文件的绝对路径module.filename ==== __filename 等价process. ...

  5. phpmyadmin后台4种拿shell方法 && php爆路径大法

    php后台拿shell要知道php的路径,文章下面将讲诉爆php路径的方法!!! 方法一: CREATE TABLE `mysql`.`xss` (`xss1` TEXT NOT NULL ); IN ...

  6. 封装的方法--读取任何路径下的properties文件中的值

    概述:我们在做项目时,经常需要从某个properties文件中读取properties文件中的值.现在我封装了一下方法,直接读取配置文件中的值. 代码如下所示: /** * Created by qi ...

  7. linux开机启动服务和chkconfig使用方法(自定义服务路径启动)

    服务概述在linux操作系统下,经常需要创建一些服务,这些服务被做成shell脚本,这些服务需要在系统启动的时候自动启动,关闭的时候自动关闭.将 需要自动启动的脚本/etc/rc.d/init.d目录 ...

  8. swift两种获取相册资源PHAsset的路径的方法(绝对路径)

    方法中使用到的phasset就是我们取到的PHAsset对象 方法一: let options = PHVideoRequestOptions() options.version = PHVideoR ...

  9. System.getProperty方法中输出路径的方法

    package codegenerator;/** *@author Eilen *@date 2017年9月27日---下午3:15:09 *@描述: *@answer */public class ...

随机推荐

  1. 【Python@Thread】threading模块

    theading模块的Thread类 属性: name 线程名 ident 线程标识符 daemon  布尔值,标示是否为守护线程 方法: __init__(target=None, name=Non ...

  2. 用户id有则更新,无则添加 使用replace into (代替 insert into)

    app登录成功后,调用后台,更新channel_id public function set_pushchannel($device,$channelid,$iv='' ) $sql = " ...

  3. 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 ...

  4. 使用InternetReadFile时要注意读取完整数据

    使用这个api读取数据后,即使数据不完整,该函数不会报任何错,GetLastError也显示操作成功.使用时要注意通过其参数判断是否读取完毕 void InternetReadFileEx(HINTE ...

  5. iOS之文件解析

    JSON JSON – OC 转换对照表 JSON OC {} NSDictonary [] NSArray "" NSString 数字 10,10.5 NSNumber NSJ ...

  6. ejabberd聊天室离线消息

    首先,xmpp服务器是基于ejabberd.离线消息模块是mod_interact,原地址地址:https://github.com /adamvduke/mod_interact: 修改后实现群聊离 ...

  7. CSS居中方法

    css居中方法非常多,根据工作的实际情况采用恰当方法,可取到事半功倍的效果. 就常见的一些居中方法整理如下: 代码如下: <div class="con"> <d ...

  8. js iframe跨域访问

    1.什么是跨域? 2.前台解决跨域几种方法 2.1 动态创建script 2.2 使用document.domain 2.3使用HTML5新属性postMessage 2.4 利用iframe和loc ...

  9. poll机制分析[转]

    所有的系统调用,基于都可以在它的名字前加上"sys_"前缀,这就是它在内核中对应的函数.比如系统调用open.read.write.poll,与之对应的内核函数为:sys_open ...

  10. Jersey客户端API调用REST风格的Web服务

    Jersey 客户端 API 基础 jersey-1.14.jar 密码: cxug 要开始使用 Jersey 客户端 API,你首先需要创建一个 com.sun.jersey .api.client ...