Spring 3.2资源文件加载问题

时间:2012-12-03 21:27:10

标签: java spring maven

我有资源文件的弹簧配置,当我在eclipse环境中执行时,它运行得非常好。但是当我将应用程序打包到JAR并执行它时,它不会归档属性文件资源。

    <bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="ignoreUnresolvablePlaceholders" value="true" />
    <property name="locations">
        <list>
            <value>classpath:Application.properties</value>
            <value>classpath:database.properties</value>
        </list>
    </property>
</bean>

<!-- define the properties file to use -->
<util:properties id="appProperties" location="classpath:Application.properties" />

当我看到jar文件时,所有文件都存在。我正在使用maven来构建程序集。

项目结构:

ProjName | | - 主     | - java     | - 资源

另外,我使用此链接使用maven配置(http://stackoverflow.com/questions/13615634/maven-build-assembly-with-dependencies)

1 个答案:

答案 0 :(得分:1)

目前还没有足够的信息来确切知道发生了什么。但在我看来,context.xml中存在一些混淆。首先,我建议用

替换以上所有内容
<context:property-placeholder location="classpath:/Application.properties, classpath:/database.properties" />