Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SPRING MVC-将外部文件用作@PropertySource_Java_Spring_Spring Mvc_Tomcat_Properties File - Fatal编程技术网

Java SPRING MVC-将外部文件用作@PropertySource

Java SPRING MVC-将外部文件用作@PropertySource,java,spring,spring-mvc,tomcat,properties-file,Java,Spring,Spring Mvc,Tomcat,Properties File,我想知道如何使用外部文件在不同的上下文中加载我的应用程序的一些属性 我知道我可以在PropertySourceannotation中传递文件。问题是文件的路径 我的意思是,它看起来需要文件的完整路径,但是不同的环境对Tomcat目录有不同的路径 我的问题是: 存储此文件的正确目录在哪里(它必须位于app dir之外,否则在每次部署时都会被删除),以及如何在应用程序中链接它 例如,现在我在tomcat的/webapps目录中创建了一个/config目录 从我的Mac电脑上,我可以这样加载文件: @

我想知道如何使用外部文件在不同的上下文中加载我的应用程序的一些属性

我知道我可以在
PropertySource
annotation中传递文件。问题是文件的路径

我的意思是,它看起来需要文件的完整路径,但是不同的环境对
Tomcat
目录有不同的路径

我的问题是: 存储此文件的正确目录在哪里(它必须位于app dir之外,否则在每次部署时都会被删除),以及如何在应用程序中链接它

例如,现在我在tomcat的
/webapps
目录中创建了一个
/config
目录

从我的Mac电脑上,我可以这样加载文件:

@PropertySource("file:/Library/Tomcat/webapps/config/db.properties" )
<context:property-placeholder
        location="${ext.properties.dir:classpath:}/db.properties" order="-1"
        ignore-unresolvable="true" ignore-resource-not-found="true" />
但我的生产应用程序在Linux服务器上,显然路径不同

有什么想法或者更好的办法来管理它吗


感谢

我有一个类似的问题需要解决,我们所做的是在服务器启动时提供属性文件的外部目录路径,如下所示:

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;

@Configuration
@PropertySources({@PropertySource("${ext.properties.dir:classpath:}/db.properties") })
public class ApplicationConfig {

}
对于基于XML的配置:

@PropertySource("file:/Library/Tomcat/webapps/config/db.properties" )
<context:property-placeholder
        location="${ext.properties.dir:classpath:}/db.properties" order="-1"
        ignore-unresolvable="true" ignore-resource-not-found="true" />
对于产品:

-Dext.properties.dir=file:/dev/Library/Tomcat/webapps/config/
-Dext.properties.dir=file:/prod/Library/Tomcat/webapps/config/