[英]Eclipse RCP cannot find applicationContext.xml
我正面臨着集成Eclipse RCP和Spring IOC的一些問題。
以下是我對該過程的處理方法。
我已經完成的步驟
在我的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文件。
我嘗試了以下方法。
在所有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.