问题描述
目录格式 spring src default package MyTest.java ShowMessage.java applicationContext.xml JRE System Library Soring 2.0 .Core log4j:WARN No appenders could be found for logger (org.springframework.context.support.FileSystemXmlApplicationContext).log4j:WARN Please initialize the log4j system properly.Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from file [D:MyEclipse 10组件springsrcaplicationContext.xml]; nested exception is java.io.FileNotFoundException: srcaplicationContext.xml (系统找不到指定的文件。)Caused by: java.io.FileNotFoundException: srcaplicationContext.xml (系统找不到指定的文件。)at java.io.FileInputStream.open(Native Method)at java.io.FileInputStream.<init>(FileInputStream.java:106)at org.springframework.core.io.FileSystemResource.getInputStream(FileSystemResource.java:85)at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:307)at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:290)at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:131)at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:147)at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:173)at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:112)at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:79)at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:101)at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:394)at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:324)at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:124)at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:68)at MyTest.main(MyTest.java:5)测试程序MyTestimport org.springframework.context.ApplicationContext;import org.springframework.context.support.FileSystemXmlApplicationContext;public class MyTest{public static void main(String[] args){ApplicationContext ctx=new FileSystemXmlApplicationContext("src/aplicationContext.xml");ShowMessage sm=(ShowMessage)ctx.getBean("myBean");sm.show();}}
解决方案
java.io.FileNotFoundException: srcaplicationContext.xml (系统找不到指定的文件。) 直接ApplicationContext ctx=new FileSystemXmlApplicationContext("aplicationContext.xml");