簡體   English   中英

Eclipse RCP找不到applicationContext.xml

[英]Eclipse RCP cannot find applicationContext.xml

我正面臨着集成Eclipse RCP和Spring IOC的一些問題。

以下是我對該過程的處理方法。

我已經完成的步驟

  1. 創建了一個Bundle(使用來自exisitng archives項目類型的插件),它包含所有Spring jar。
  2. 使用視圖創建了一個簡單的Hello RCP應用程序。
  3. 添加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();

這引發了錯誤

找不到文件[D:\\ applicationContext.xml]中定義的名稱為“JGID”的bean的類[st.Triangle]; 嵌套異常是java.lang.ClassNotFoundException:st.Triangle

我該如何解決這個錯誤?

作為一種解決方法,我嘗試了另一種方式,我也失敗了,如下所示,使用ClassPathXmlApplicationContext

ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");

以下是錯誤

!MESSAGE無法創建視圖ID st.view:IOException從類路徑資源[applicationContext.xml]解析XML文檔; 嵌套異常是java.io.FileNotFoundException:類路徑資源[applicationContext.xml]無法打開,因為它不存在!STACK 0 java.io.FileNotFoundException:類路徑資源[applicationContext.xml]無法打開

我的Eclipse RCP applcication中的上述代碼行,它在哪里檢查或查找xml文件。

我嘗試了以下方法。

  • 將applicationContext.xml放在src文件夾中。
  • 在項目文件夾中。
  • Inisde包。

在所有3個案例中,它都說FileNotFoundException 我應該在哪里放置applicationContext.xml文件以使applicationContext引用找到它?

spring-context.xml放在應用程序的類路徑中,並且為了調用它,您需要以下代碼

ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-context.xml");
            Triangle triangle = (Triangle) ctx.getBean("jgid");
             triangle.draw();  

這個網站被盜

你確定Triangle在“ctx”類路徑中嗎?

你可以在另一個簡單的bean中即時通訊嗎?

<bean id="str" class="java.lang.String" value="Hello World">

然后打電話

String str= (String) ctx.getBean("str");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM