我遇到了主題中描述的這個問題。我打印了工作目錄以確定我在哪里運行。我試過以下代碼: public static void main(String[] args) { System.out.println("Working Directory = " + System.getProperty("user.dir")); //load the spring configuration file ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); ...}并將 xml 放在項目根目錄和目標目錄中,用于上面的第一次和第二次嘗試,并在 src 目錄中進行第二次和第三次嘗試(即使我不認為這是正確的地方,但目前所有的都是留給我的是向任何方向射擊)。Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)這是 manifest.mf 文件:Manifest-Version: 1.0Built-By: TalTClass-Path: lib/spring-core-5.0.8.RELEASE.jar lib/spring-jcl-5.0.8.REL EASE.jar lib/spring-context-3.0.2.RELEASE.jar lib/spring-aop-3.0.2.RE LEASE.jar lib/aopalliance-1.0.jar lib/spring-beans-3.0.2.RELEASE.jar lib/spring-expression-3.0.2.RELEASE.jar lib/spring-asm-3.0.2.RELEASE. jarCreated-By: Apache Maven 3.5.4Build-Jdk: 1.8.0_171Main-Class: ttt.springdemo.HelloSpringApp請指教。謝謝。
2 回答

繁星點點滴滴
TA貢獻1803條經(jīng)驗 獲得超3個贊
寫出正確的路徑
ApplicationContext context = new ClassPathXmlApplicationContext("packageName/config.xml");
添加回答
舉報
0/150
提交
取消