我在集成Eclipse RCP和Spring IOC时遇到了一些问题。
下面是我对这个过程的处理方法。
我所做的步骤
-
创建了一个Bundle(使用现有归档项目类型中的插件),其中包含所有Spring jar。
-
创建了一个带有视图的简单HelloRCP应用程序。
-
将Bundle添加为RCP项目的依赖项(步骤2)
在我的RCP项目中创建了一个简单的类,其对象必须通过applicationContext.xml实例化。
public class Triangle {
public void draw(){
System.out.println("Traingle drawn");
}
}
我的applicationContext.xml代码
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<bean id="JGID" class="st.Triangle"/>
</beans>
获取applicationContext.xml的My视图的代码片段如下
ApplicationContext applicationContext = new FileSystemXmlApplicationContext("D:/applicationContext.xml");
Triangle triangle = (Triangle) applicationContext.getBean("JGID");
triangle.draw();
这会引发错误
找不到中定义的名为“JGID”的bean的类[st.Triangle]
文件[D:\applicationContext.xml];嵌套异常为
java.lang.ClassNotFoundException异常:圣三角
如何解决此错误?
作为一种变通方法,我尝试了另一种方法,但也失败了,如下所示,即使用ClassPathXmlApplicationContext
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
以下是错误
!MESSAGE无法创建视图ID st.view:IO从类路径资源[applicationContext.XML]解析XML文档时出现异常;嵌套异常是java.io.FileNotFoundException:类路径资源
[applicationContext.xml]不存在,因此无法打开
!STACK 0 java.io.FileNotFoundException:无法打开类路径资源[applicationContext.xml]
上面的代码行在我的EclipseRCP应用程序中,它在哪里检查或查找xml文件。
我尝试了以下方法。
-
已将applicationContext.xml放置在src文件夹中。
-
在项目文件夹中。
-
在包裹里。
报告称,在所有三种情况下
FileNotFoundException
.我应该把
applicationContext.xml
文件以制作
applicationContext
找到它的参考?