2015-06-26 22 views
0

enter image description hereSpring應用程序上下文無法找到下maven的資源文件夾

我使用maven在我的項目&我已經把database.properties下的文件 Maven的資源文件夾屬性的文件。

我訪問它在Spring應用程序上下文

<context:property-placeholder location="classpath:database.properties" /> 

但我不明白爲什麼我收到這個文件沒有發現在服務器啓動的錯誤。

無法加載屬性;嵌套的例外是 java.io.FileNotFoundException:類路徑資源 ,因爲它不存在

爲了我的任何資源將被自動添加到類路徑中的資源文件夾下把知識[database.properties]無法打開由maven。

的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.myapp</groupId> 
    <artifactId>myapp</artifactId> 
    <packaging>war</packaging> 
    <version>0.0.1-SNAPSHOT</version> 
    <name>myapp Maven Webapp</name> 
    <url>http://maven.apache.org</url> 
    <dependencies> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>3.8.1</version> 
      <scope>test</scope> 
     </dependency> 
    </dependencies> 
    <build> 
     <finalName>myapp</finalName> 
    </build> 
</project> 

注:好像有一些問題,日食月神的M2E插件。在Juno &中執行相同的代碼,它工作正常。

+0

您是否打包該應用程序? –

+0

我不明白你是什麼意思,但我已經添加了我的pom.xml。 – underdog

+0

http://stackoverflow.com/questions/14499072/location-of-applicationcontext-xml-and-properties-file-in-spring有點類似的問題..看看是否有幫助 – sampath

回答

1

這還不足以用maven構建可部署的war文件。你至少需要戰爭插件。有一個徹底的教程在這裏:

http://crunchify.com/how-to-create-a-war-file-from-eclipse-using-maven-plugin-apache-maven-war-plugin-usage/

你的POM看起來就像下面,你會需要MVN運行全新安裝的對抗。

另外,我看到你有一個春天的應用程序,在pom文件中的彈簧依賴關係在哪裏?

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>CrunchifyTutorial</groupId> 
    <artifactId>CrunchifyTutorial</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>war</packaging> 
    <build> 
     <sourceDirectory>src</sourceDirectory> 
     <plugins> 
      <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.1</version> 
       <configuration> 
        <source>1.7</source> 
        <target>1.7</target> 
       </configuration> 
      </plugin> 
      <plugin> 
       <artifactId>maven-war-plugin</artifactId> 
       <version>2.4</version> 
       <configuration> 
        <warSourceDirectory>WebContent</warSourceDirectory> 
        <failOnMissingWebXml>false</failOnMissingWebXml> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
    <dependencies> 
     <dependency> 
      <groupId>javax.servlet</groupId> 
      <artifactId>servlet-api</artifactId> 
      <version>2.5</version> 
     </dependency> 
    </dependencies> 
</project> 
+0

我已經跳過依賴關係,以保持POM問題簡短。除此之外,我正在使用m2e插件,我認爲它會默認使用編譯器和資源,maven-war插件。在pom中明確添加。沒有運氣仍然是同一個prb。 – underdog

+0

在日食朱諾試過,在那裏工作得很好。問題與月神的m2e插件。 – underdog

+0

很酷。也許事情已經改變,但我總是不得不添加額外的插件。 –

相關問題