簡體   English   中英

在春季如何將xml bean配置文件導入到@configuration類?

[英]How can I import a xml bean configuration file to a @configuration class in spring?

我現在要在春季應用程序中導入一個巨大的xml。

檢查文檔, http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/Configuration.html我發現我可以做這樣的事情

@PropertySource("classpath:/resources/applicationContex.xml")

我的資源文件夾在/src/main

但是我收到文件不存在錯誤,知道這是否是正確的方法嗎? 還是我的路徑定義錯誤?

正如@Sotirios在他的評論中所說,您應該刪除/resources前綴。 但是您還會使用錯誤的注釋: @PropertySource用於導入屬性文件。 您應該使用@ImportResource批注。

@Configuration
@ImportResource("classpath:applicationContext.xml")
public class AppConfig {

    // define more beans, wire beans defined in the xml, etc
}

注意:您可能還會輸入錯誤:您指向的文件名為applicationContex.xml 應該不是applicationContext.xml嗎? (請注意.xml擴展名前的最后一個t )。

暫無
暫無

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

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