博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
FileSystemXmlApplicationContext方法的绝对路径问题
阅读量:5833 次
发布时间:2019-06-18

本文共 3782 字,大约阅读时间需要 12 分钟。

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.xmlorg.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.
(FileSystemXmlApplicationContext.java:140) at org.springframework.context.support.FileSystemXmlApplicationContext.
(FileSystemXmlApplicationContext.java:84) at com.newland.sri.utap.ats.AgentServer.
(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.
(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");    }

 

转载于:https://www.cnblogs.com/garfieldcgf/p/5619755.html

你可能感兴趣的文章
OllyDBG 入门系列教学--让你瞬间成为破解高手
查看>>
Dubbo点滴(2)之集群容错
查看>>
检测不到兼容的键盘驱动程序
查看>>
listbox用法
查看>>
冲刺第九天 1.10 THU
查看>>
传值方式:ajax技术和普通传值方式
查看>>
Linux-网络连接-(VMware与CentOS)
查看>>
寻找链表相交节点
查看>>
AS3——禁止swf缩放
查看>>
linq 学习笔记之 Linq基本子句
查看>>
[Js]布局转换
查看>>
Hot Bath
查看>>
国内常用NTP服务器地址及
查看>>
Java annotation 自定义注释@interface的用法
查看>>
Apache Spark 章节1
查看>>
phpcms与discuz的ucenter整合
查看>>
Linux crontab定时执行任务
查看>>
mysql root密码重置
查看>>
33蛇形填数
查看>>
选择排序
查看>>