我遇到了主题中描述的这个问题。我打印了工作目录以确定我在哪里运行。我试过以下代码: 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条经验 获得超3个赞
写出正确的路径
ApplicationContext context = new ClassPathXmlApplicationContext("packageName/config.xml");
添加回答
举报
0/150
提交
取消