2010-03-10 48 views
0

我有一個使用Maven編譯/構建的Spring Web項目。建設該項目沒有問題。我正嘗試在Tomcat(v6)服務器上的Eclipse(3.3.2)中運行項目。在Tomcat服務器上的Eclipse中執行Spring Web項目的問題

作爲Spring項目的一部分,我在WEB-INF目錄中有一個spring-servlet.xml文件。該文件包含具有數據源配置的另一個資源xml文件。

<import resource="classpath:${datasourceInclude}.xml"/> 

現在,當項目使用Maven編譯,它解決了變量$ {} datasourceInclude與導致彈簧servlet.xml中與正確的價值觀適當的值設置。

<import resource="classpath:datasourceLocal.xml"/> 

但是,當我試圖運行在Eclipse(Tomcat)的項目,我收到以下錯誤:

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:${datasourceInclude}.xml] 
Offending resource: ServletContext resource [/WEB-INF/spring-servlet.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [${datasourceInclude}.xml]; nested exception is java.io.FileNotFoundException: class path resource [${datasourceInclude}.xml] cannot be opened because it does not exist 
    at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68) 
... 
... 

基本上當我啓動Tomcat的,它試圖從挑彈簧servlet.xml中/ src/main/webapp /具有$ {datasourceInclude}變量的WEB-INF文件夾。

任何人都可以告訴我如何解決此問題,以便我不必更改spring-servlet.xml並添加硬代碼值來代替$ {datasourceInclude}變量。

回答

1

嘗試將war:inplace添加到在Maven項目配置頁面中爲資源過濾執行的目標列表中。

右鍵單擊您的項目,然後去屬性>的Maven>生命週期映射並添加war:inplace目標來調用資源更改,如下圖所示:

alt text http://img519.imageshack.us/img519/2817/screenshot009d.png

+0

我有同樣的問題,STS 2.7,m2eclipse和在這種情況下,tomcat 7現在內部使用,任何其他想法爲什麼這不被調用或如何追蹤問題? – chrismarx

+0

升級到STS 2.8,新的m2e支持,過濾效果非常好, – chrismarx

0

誰負責解析Spring XML中的屬性/變量名?這是通過Maven在編譯時完成的,還是應該在運行時發生?如果在運行時,您是否使用Spring的PropertyPlaceholderConfigurer

+0

這由Maven在編譯時完成。我已經指定了幾個加載具有變量值的資源包文件的maven配置文件。 –

+0

那麼從Eclipse運行時你如何期待它的工作?您是否在Eclipse中使用Maven插件,如M2E? – SteveD

+0

是的,我正在使用適用於Eclipse的Maven插件M2E。我的問題是如何配置Eclipse,以便在Tomcat中加載之前更改spring-servlet.xml文件中的變量。 –

相關問題