這非常奇怪,我在Eclipse中運行項目沒有問題,但如果運行 java -jar xxx.jar
(導出到Runnable Jar)classpath resource [spring/config/BeanLocations.xml]無法打開,因爲它不存在
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStore Exception: IOException parsing XML document from class path resource [spring/config/BeanLocations.xml]; nested exception is java.io.FileNotFoundException: classpath resource [spring/config/BeanLocations.xml] cannot be opened because it does not exist at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea nDefinitions(XmlBeanDefinitionReader.java:349) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea nDefinitions(XmlBeanDefinitionReader.java:310) at org.springframework.beans.factory.support.AbstractBeanDefinitionReade r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143) at org.springframework.beans.factory.support.AbstractBeanDefinitionReade r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178) at org.springframework.beans.factory.support.AbstractBeanDefinitionReade r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149) at org.springframework.beans.factory.support.AbstractBeanDefinitionReade r.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212) at org.springframework.context.support.AbstractXmlApplicationContext.loa dBeanDefinitions(AbstractXmlApplicationContext.java:113) at org.springframework.context.support.AbstractXmlApplicationContext.loa dBeanDefinitions(AbstractXmlApplicationContext.java:80) at org.springframework.context.support.AbstractRefreshableApplicationCon text.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123) at org.springframework.context.support.AbstractApplicationContext.obtain FreshBeanFactory(AbstractApplicationContext.java:422) at org.springframework.context.support.AbstractApplicationContext.refres h(AbstractApplicationContext.java:352) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83) at my.lincdoc.manager.ProposalManager.getAllProposalInfo(ProposalManager .java:183) at my.lincdoc.manager.ProposalManager.eliminateDuplicate(ProposalManager .java:194) at my.lincdoc.controller.ProposalController.RetrieveProposalForm(Proposa lController.java:70) at my.lincdoc.common.App.main(App.java:16) Caused by: java.io.FileNotFoundException: class path resource [spring/config/Bea nLocations.xml] cannot be opened because it does not exist at org.springframework.core.io.ClassPathResource.getInputStream(ClassPat hResource.java:143) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBea nDefinitions(XmlBeanDefinitionReader.java:336) ... 16 more
我把BeanLocations.xml裏面的文件夾
ApplicationContext appContext = new ClassPathXmlApplicationContext("spring/config/BeanLocations.xml");
ProposalFormBo proposalFormBo = (ProposalFormBo) appContext.getBean("proposalBo");
當你解壓縮jar文件時,你看到'spring/config/BeanLocations.xml'文件,其中'spring'文件夾從你解壓文件的位置開始? – Santosh