1

我应该将我的 .properties 文件保存在 java 项目中的哪里,以便它应该在 war 文件之外。我应该遵循哪些步骤来实施

4

1 回答 1

0

In addition to the Nawnit Sen's comment.

As for me I've put it in local disk file system.

Also I've granted my tomcat user all privileges to the folder.

In the root-context.xml file I've registered two properties files for both cases(I develop on a Windows and deploy on a Linux). You could register only one properties file

<context:property-placeholder location="file:/path/to/application.properties" order="1" ignore-resource-not-found="true" ignore-unresolvable="true" />
<context:property-placeholder location="file:C:/path/to/application.properties" order="2" ignore-resource-not-found="true" ignore-unresolvable="true" />

Now in your class you could get the property like this

import org.springframework.beans.factory.annotation.Value;

@Value("${someProperty}")  
private String yourProperty;
于 2018-09-27T02:26:35.923 回答