代码之家  ›  专栏  ›  技术社区  ›  Nick M

无法在Spring Web应用程序中打开属性文件

  •  0
  • Nick M  · 技术社区  · 11 年前

    我正试图在tomcat上设置几个webapp,但没有一个财产文件被选中

    2014-02-19 15:47:02,106 - WARN  org.springframework.core.io.support.PropertiesLoaderSupport - Could not load properties from class
     path resource [indexing.properties]: class path resource [indexing.properties] cannot be opened because it does not exist
    2014-02-19 15:47:02,110 - WARN  org.springframework.core.io.support.PropertiesLoaderSupport - Could not load properties from class
     path resource [user-service.properties]: class path resource [user-service.properties] cannot be opened because it does not exist
    2014-02-19 15:47:05,169 - WARN  com.cubeia.backoffice.users.Configuration - No user-service.properties configuration file found. U
    sing default.
    

    /WEB-INF/classes/service.xml文件具有以下定义:

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:default-indexing.properties</value>
                <value>classpath:indexing.properties</value>
            </list>
        </property>
        <property name="ignoreResourceNotFound" value="true" />
    </bean>
    

    我试着在我能想到的任何地方复制.properties文件。tomcat/conf、tomcat/lib、tomcat/conf/Catalina、tomcat/conf/Catalina/lolocalhost、webapps//WEB-INF/、webapps//WEB-INF/classes/,然后也在与实际.class文件相同的目录中,临时目录,您可以将其命名。只是不会拾取它。

    稍后编辑:我还尝试了/WEB-INF/classes、WEB-INF/、tomcat/conf、tomcat/lib、classpath*:。。。基本上所有可能的组合。

    2 回复  |  直到 7 年前
        1
  •  1
  •   Software Engineer    11 年前

    您应该将财产文件放在webapp的src/main/resources目录中。然后,Maven(我假设您正在使用Maven)会将此文件复制到您的WEB-INF/classes目录中,并将其放在类路径中。如果你按照@arahant的答案,一切都会好起来的。

        2
  •  0
  •   arahant    11 年前

    这个 classpath: 指向WEB-INF/classes

    如果您使用的是SpringMVC 3,可以使用 util:properties 注释。以下是工作配置的摘录。

    <util:properties id="emailProperties" location="classpath:../email.properties"/>
    

    这里我的email.properties位于WEB-INF目录中,因此../在文件名之前

    util架构位于 http://www.springframework.org/schema/util/spring-util-3.0.xsd