首页 新闻 会员 周边 捐助

java spring的beans.xml放在哪里的?

0
悬赏园豆:5 [已解决问题] 解决于 2016-11-04 10:37

参照这篇文章写的一个小demo http://blog.csdn.net/zhangerqing/article/details/8546049,但是一直报这个错

复制代码
2016-11-4 9:46:37 org.springframework.context.support.AbstractApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1dff3a2: startup date [Fri Nov 04 09:46:37 CST 2016]; root of context hierarchy
2016-11-4 9:46:37 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [beans.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [beans.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:174)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
    at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:527)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:441)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at com.adam.java.spring.DITest.main(DITest.java:11)
Caused by: java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not exist
    at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:157)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
    ... 13 more
复制代码
小小乌龟把头藏的主页 小小乌龟把头藏 | 初学一级 | 园豆:9
提问于:2016-11-04 09:52
< >
分享
最佳答案
0

他只告诉你需要bean.xml,没告诉你web.xml里面要加入监听和bean.xml的路径

收获园豆:5
[3] | 小虾三级 |园豆:1174 | 2016-11-04 10:06

这文章也是醉了,他建的也不是web

小小乌龟把头藏 | 园豆:9 (初学一级) | 2016-11-04 10:09

成功了!我把项目改成web项目,然后把读取xml文件的函数改成这个就可以了

ApplicationContext atx=new FileSystemXmlApplicationContext("/WebRoot/WEB-INF/beans.xml");

非常感谢!

小小乌龟把头藏 | 园豆:9 (初学一级) | 2016-11-04 10:37
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册