XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource(
"application-context.xml"));
我的 application-context.xml 位于 com.myname.mysubpackage.spring.application-context.xml
如何让它加载...
INFO - XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [application-context.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [application-context.xml]; nested exception is java.io.FileNotFoundException: class path resource [application-context.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.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:73)
at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:61)
at com.mysticcoders.mysticpaste.services.CrudService.main(CrudService.java:9)
Caused by: java.io.FileNotFoundException: class path resource [application-context.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:141)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
... 4 more
我收到此错误。
最佳答案
new XmlBeanFactory(new ClassPathResource(
"application-context.xml"));
您的文件应该直接位于默认包中。
如果您使用maven,那么最好的位置是将其放在resource
目录中
关于java - 加载应用程序上下文.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4545968/