我遇到了主題中描述的這個(gè)問(wèn)題。我打印了工作目錄以確定我在哪里運(yùn)行。我試過(guò)以下代碼: 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 放在項(xiàng)目根目錄和目標(biāo)目錄中,用于上面的第一次和第二次嘗試,并在 src 目錄中進(jìn)行第二次和第三次嘗試(即使我不認(rèn)為這是正確的地方,但目前所有的都是留給我的是向任何方向射擊)。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請(qǐng)指教。謝謝。
Spring:調(diào)用 new ClassPathXmlApplicationContext()
桃花長(zhǎng)相依
2021-08-13 15:27:12