我試圖將一個簡單的Spring 2.5 hello世界項目(從Spring Recipes)轉換爲3.0。對於初學者,我創建了一個簡單的Spring實用程序項目(來自新項目的Spring Template Project選項)。如何將Spring 2.5項目轉換爲3.0
我已將源代碼複製到3.0項目的「src/main/java/com.apress.springrecipes.hello」包中。在那裏,bean配置文件位於「src/main/resources/META-INF/spring/app-context.xml」。但是,2.5 hello world調用文件「beans.xml」,它在項目的根路徑中創建。 Main類的代碼如下所示:
public static void main(String[] args) {
ApplicationContext context =
new ClassPathXmlApplicationContext("beans.xml");
HelloWorld helloWorld = (HelloWorld) context.getBean("helloWorld");
helloWorld.hello();
}
如何更改此選項以查找新的app-context.xml?
謝謝。爲了將來的參考,如果有人想在STS中設置類路徑來實現這樣的目標,請選擇Run,Run Configurations。單擊用戶條目,前進,添加外部文件夾,然後深入到配置文件前的路徑。在我的情況下,它是/ SpringRecipesHelloWord/src/main/resources/META-INF/spring。 – 2012-02-07 04:19:14