![](/img/trans.png)
[英]How to inject a string that contains ${…} in spring application.properites
[英]Cannot Open properites file in Spring Web application
我正在嘗試在tomcat上設置幾個Web應用程序,但是沒有獲取任何屬性文件
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>
我嘗試將.property文件復制到我能想到的任何地方。 tomcat / conf,tomcat / lib,tomcat / conf / Catalina,tomcat / conf / catalina / localhost,webapps // WEB-INF /,webapps // WEB-INF / classes /,然后也位於與實際目錄相同的目錄中。類文件,臨時目錄,您命名。 只是不會撿起來。
以后的編輯:我還嘗試了/ WEB-INF / classes,WEB-INF /,tomcat / conf,tomcat / lib,classpath *:...等所有可能的組合。
您應該將屬性文件放在webapp的src / main / resources目錄中。 然后,Maven(假設您正在使用maven)會將文件復制到您的WEB-INF / classes目錄中,並將其放在類路徑中。 如果您隨后遵循@arahant的回答,一切都會好起來的。
classpath:
指向WEB-INF / classs
如果您使用的是Spring MVC 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.