Eclipse RCP と Spring IOC の統合に関するいくつかの問題に直面しています。
以下は、プロセスに対する私のアプローチです。
私が行った手順
- すべての Spring jar を含むバンドル (既存のアーカイブ プロジェクト タイプのプラグインを使用) を作成しました。
- ビューを使用してシンプルな Hello RCP アプリケーションを作成しました。
- バンドルを依存関係として RCP プロジェクトに追加しました (step2)
オブジェクトがapplicationContext.xmlを介してインスタンス化する必要がある私のRCPプロジェクトに単純なクラスを作成しました。
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 をフェッチしているビューのコード スニペット部分は以下のとおりです。
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 を作成できません: クラス パス リソース [applicationContext.xml] から XML ドキュメントを解析中に IOException が発生しました。ネストされた例外は java.io.FileNotFoundException: クラスパス リソース [applicationContext.xml] が存在しないため開けません!STACK 0 java.io.FileNotFoundException: クラスパス リソース [applicationContext.xml] を開けません
私のEclipse RCPアプリケーションの上記のコード行は、どこでxmlファイルをチェックまたは検索しますか。
以下の方法を試しました。
- applicationContext.xml を src フォルダーに配置しました。
- プロジェクトフォルダーにあります。
- パッケージに入れます。
3つのケースすべてで、それは言うFileNotFoundException
. ファイルを見つけるための参照を作成するには、applicationContext.xml
ファイルをどこに配置すればよいですか?applicationContext