[英]loading xml application context ioexception spring
I'm starting to learn the Spring framework and when i run the application i get an IOException saying that the xml file does not exist but it is located in the root folder. 我开始学习Spring框架,当我运行该应用程序时,我得到一个IOException,它表示xml文件不存在,但它位于根文件夹中。 Here's the little code: package org.koushik.javabrains; 这是小代码:org.koushik.javabrains包;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class DrawingApp {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
Triangle triangle = (Triangle)context.getBean("triangle");
triangle.draw();
}
}
The xml: xml:
<beans>
<bean id="triangle" class="org.koushik.javabrains.Triangle">
<property name="type" value="Equilateral"/>
</bean>
</beans>
Here's how the project looks like: 项目外观如下:
This worked perfectly when i used the BeanFactory interface but with the ApplicationContext i get this error. 当我使用BeanFactory接口但与ApplicationContext一起使用时,出现此错误,效果很好。 I tried putting the xml file i the src folder but it didn't work either. 我尝试将xml文件放在src文件夹中,但也没有用。 Thanks for the help 谢谢您的帮助
您需要将spring.xml放在src文件夹中,而不是在根文件夹中,因为ClassPathXmlApplicationContext从类路径中读取。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.