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方法的绝对路径问题的更多相关文章

  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. 彻底解决tap“点透”,提升移动端点击响应速度

    申明!!!最后发现判断有误,各位读读就好,正在研究中.....尼玛水太深了 前言 近期使用tap事件为老夫带来了这样那样的问题,其中一个问题是解决了点透还需要将原来一个个click变为tap,这样的话 ...

  2. hdu_5862_Counting Intersections(扫描线)

    题目链接:hdu_5862_Counting Intersections 题意: 给你与坐标轴平行的线段,问你交点数 题解: 实质就是扫描线,这里我用树状数组来记录,所有线段按X坐标排序,遇到横线段的 ...

  3. lua 中操作系统库

    time 和 date 两个函数在lua中实现所有的时钟查询功能. 函数time在没有参数时返回当前时钟的数值.(在许多操作系统中,该数值是距离某个特定时间的秒数). date是time的一种“反函数 ...

  4. CentOS postgresql9.4

    yum install http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-redhat94-9.4-1.noarch.rpm Once t ...

  5. Bmob Androidstudio配置

    AndroidStudio配置 鉴于目前Google官方推荐使用 Android Studio 进行Android项目开发,自 V3.4.2 开始,Bmob Android SDK 可以使用Gradl ...

  6. Meta标签中的属性及含义

    一.Meta标签中的format-detection属性及含义 format-detection翻译成中文的意思是“格式检测”,顾名思义,它是用来检测html里的一些格式的,那关于meta的forma ...

  7. 杭电OJ分类

    基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029.1032.1037.1040.1048.1056.1058.1 ...

  8. Screen tearing

    Umm, screen tearing happens when the frame rate and the monitor refresh rate don't match.  When that ...

  9. STM32F446 OTG_FS_DP/DM调试

    之前项目用STM32F207,现在升级到用STM32F446处理器,用到USB的OTG_FS模式接法: 1.USB只连接了DP/DM 2.DP需上拉1.5K的电阻到3.3V 3.PA9(VBUS) 和 ...

  10. java 正则

    ava - 正则表达式 - Pattern - Matcher 2013-08-21 14:35 3325人阅读 评论(0) 收藏 举报  分类: JavaSE(30)  版权声明:本文为博主原创文章 ...