简体   繁体   English

Eclipse RCP找不到applicationContext.xml

[英]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 我已经完成的步骤

  1. Created a Bundle (Using plug-in from exisitng archives project type) which has all Spring jars. 创建了一个Bundle(使用来自exisitng archives项目类型的插件),它包含所有Spring jar。
  2. Created a Simple Hello RCP application with a view. 使用视图创建了一个简单的Hello RCP应用程序。
  3. Added the Bundle as a dependency to the RCP project(step2) 添加Bundle作为RCP项目的依赖项(步骤2)

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. 我尝试了以下方法。

  • Placed applicationContext.xml in src folder. 将applicationContext.xml放在src文件夹中。
  • At the project folder. 在项目文件夹中。
  • Inisde the package. Inisde包。

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();  

Stolen from This site 这个网站被盗

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM