The absolute path problem of the Filesystemxmlapplicationcontext method

Source: Internet
Author: User

Public Agentserver (Socket c,string confdir) {
This.client = C;
ApplicationContext ac = new Filesystemxmlapplicationcontext (confdir);
This.atsmgr = (atsmgr) ac.getbean ("Atsmgr");
}

Use the Filesystemxmlapplicationcontext method to prepare to take the bean in the container, there is no problem in the window environment, but put on Jenkins found always error, said the file can not find:

/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:60V) 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.O Pen (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)    ... More

To view the source code discovery, the Filesystemxmlapplicationcontext method handles the path:

    protected Resource Getresourcebypath (String path) {        ifnull && Path.startswith ("/") ) {            = path.substring (1);        }         return New Filesystemresource (path);}    }

With an absolute path, the first slash is removed (and I don't know why, I'm going), so put a slash in front of the code to solve the problem, the code passes:

     Public agentserver (Socket c,string confdir) {        this. client = C;          New Filesystemxmlapplicationcontext ("/" + Confdir);         this. Atsmgr = (atsmgr) ac.getbean ("Atsmgr");    }

The absolute path problem of the Filesystemxmlapplicationcontext method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.