【发布时间】:2012-03-28 07:38:49
【问题描述】:
我开始学习 Spring 框架,当我运行应用程序时,我收到一个 IOException,说 xml 文件不存在,但它位于根文件夹中。这是小代码:package 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();
}
}
xml:
<beans>
<bean id="triangle" class="org.koushik.javabrains.Triangle">
<property name="type" value="Equilateral"/>
</bean>
</beans>
项目如下所示:
当我使用 BeanFactory 接口但使用 ApplicationContext 时,我得到了这个错误。我尝试将 xml 文件放入 src 文件夹,但它也不起作用。感谢您的帮助
【问题讨论】: