|
错误提示,如下:
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from file [D:\eclipse_Indigo\workspace\spring_PointcutAdviser\applicationContext.xml]; nested exception is java.io.FileNotFoundException: applicationContext.xml (系统找不到指定的文件。) Caused by: java.io.FileNotFoundException: applicationContext.xml (系统找不到指定的文件。) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(Unknown Source) 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 test.main(test.java:12)
找到test.java:12,该语句为:ApplicationContext ac=new FileSystemXmlApplicationContext("applicationContext.xml");
解决办法,有两种,如下:
第一种:通过FileSystemXmlApplicationContext读取配置文件时,需要使用绝对路径。因此,只需要将上述语句改为如下情形:
ApplicationContext ac=new FileSystemXmlApplicationContext("D:\\eclipse_Indigo\\workspace\\spring_PointcutAdviser\\src\\applicationContext.xml");
这里要注意路径的写法,在电脑中显示的路径是“D:\eclipse_Indigo\workspace\spring_PointcutAdviser\src”,这里必须改写,否则无效。
第二种: 采用这条语句ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");ClassPathXmlApplicationContext是通过相对路径来读取配置文件的。
可以参考相关拓展:http://blog.163.com/wjf_j2ee2009/blog/static/1326020002010460395919/。 |