[英]Eclipse RCP cannot find applicationContext.xml
I am facing some issues integrating Eclipse RCP and Spring IOC. 我正面临着集成Eclipse RCP和Spring IOC的一些问题。
Below is my approach to the process. 以下是我对该过程的处理方法。
Steps I've done 我已经完成的步骤
Created a simple class in my RCP project whose object has to instantiated through applicationContext.xml. 在我的RCP项目中创建了一个简单的类,其对象必须通过applicationContext.xml实例化。
public class Triangle {
public void draw(){
System.out.println("Traingle drawn");
}
}
My applicationContext.xml code 我的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>
A code snippet part of My view where I'm fetching applicationContext.xml is as below 我正在获取applicationContext.xml的My视图的代码片段部分如下所示
ApplicationContext applicationContext = new FileSystemXmlApplicationContext("D:/applicationContext.xml");
Triangle triangle = (Triangle) applicationContext.getBean("JGID");
triangle.draw();
this throws error 这引发了错误
Cannot find class [st.Triangle] for bean with name 'JGID' defined in file [D:\\applicationContext.xml];
找不到文件[D:\\ applicationContext.xml]中定义的名称为“JGID”的bean的类[st.Triangle]; nested exception is java.lang.ClassNotFoundException: st.Triangle
嵌套异常是java.lang.ClassNotFoundException:st.Triangle
How do I resolve this error ? 我该如何解决这个错误?
As a workaround I tried the other way, also I failed as in below ie., using ClassPathXmlApplicationContext 作为一种解决方法,我尝试了另一种方式,我也失败了,如下所示,使用ClassPathXmlApplicationContext
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
Below is the error 以下是错误
!MESSAGE Unable to create view ID st.view: IOException parsing XML document from class path resource [applicationContext.xml];
!MESSAGE无法创建视图ID st.view:IOException从类路径资源[applicationContext.xml]解析XML文档; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist !STACK 0 java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened
嵌套异常是java.io.FileNotFoundException:类路径资源[applicationContext.xml]无法打开,因为它不存在!STACK 0 java.io.FileNotFoundException:类路径资源[applicationContext.xml]无法打开
The above code line in my Eclipse RCP applcication, where does it check or look for the xml file. 我的Eclipse RCP applcication中的上述代码行,它在哪里检查或查找xml文件。
I tried the following ways. 我尝试了以下方法。
In all the 3 cases, it says FileNotFoundException
. 在所有3个案例中,它都说
FileNotFoundException
。 Where should I place the applicationContext.xml
file to make the applicationContext
reference to find it? 我应该在哪里放置
applicationContext.xml
文件以使applicationContext
引用找到它?
Place the spring-context.xml
in the class path of your application and in order to invoke it, you need the following code 将
spring-context.xml
放在应用程序的类路径中,并且为了调用它,您需要以下代码
ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-context.xml");
Triangle triangle = (Triangle) ctx.getBean("jgid");
triangle.draw();
are you sure that Triangle is in "ctx" classpath? 你确定Triangle在“ctx”类路径中吗?
can you instantinate another simple bean for example 你可以在另一个简单的bean中即时通讯吗?
<bean id="str" class="java.lang.String" value="Hello World">
and then call 然后打电话
String str= (String) ctx.getBean("str");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.