关于application.properties文件和环境变量 [英] Regarding application.properties file and environment variable

查看:5013
本文介绍了关于application.properties文件和环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  pathToInputFile = 

在我的application.properties文件中, kcs / data / incoming / ready /
pathToInputFileProcess = / kcs / data / incoming / work /

如果我有以下方式使用环境变量Java程序不能识别路径



环境变量TOM_DATA设置为/ kcs

  pathToInputFile = $ {TOM_DATA} / data / incoming / ready / 
pathToInputFileProcess = $ {TOM_DATA} / data / incoming / work /

>解决方案

您可以在您的属性文件中放置环境变量,但Java不会自动将它们识别为环境变量,因此不会解析它们。



要执行此操作,您将必须解析值并解析您找到的任何环境变量。



您可以获取环境Java中的变量使用各种方法。例如: Map< String,String> env = System.getenv();



这里有一个基本的教程: http://java.sun.com/docs/books/tutorial/essential/environment/env.html



希望这有一些帮助。


In my application.properties file if I have the path configured like below Java successfully recognizes the path.

pathToInputFile=/kcs/data/incoming/ready/
pathToInputFileProcess=/kcs/data/incoming/work/

If I have the below way using environment variable Java program doesn't recognize the path

Environmental variable TOM_DATA is set as /kcs

pathToInputFile=${TOM_DATA}/data/incoming/ready/
pathToInputFileProcess=${TOM_DATA}/data/incoming/work/

Can I use environment variable inside application.properties file?

解决方案

You can put environment variables in your properties file, but Java will not automatically recognise them as environment variables and therefore will not resolve them.

In order to do this you will have to parse the values and resolve any environment variables you find.

You can get at environment variables from Java using various methods. For example: Map<String, String> env = System.getenv();

There's a basic tutorial here: http://java.sun.com/docs/books/tutorial/essential/environment/env.html

Hope that's of some help.

这篇关于关于application.properties文件和环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆