简体   繁体   English

Java设置持久化环境变量

[英]Java set persistent environment variable

I have set environment varible through 我通过设置环境变量

System.setProperty("mykey" : "itsvalue");

I am retrieving it as : 我将其检索为:

System.getProperty("mykey");

I get the mykey retrieved properly, but when I restart my service, mykey also get erased. 我可以正确检索到mykey,但是当我重新启动服务时,mykey也将被删除。 How to save the mykey so that it remains persistent even after service restart? 如何保存mykey,使其即使在服务重新启动后仍保持不变?

I don't want to save it in database or cache. 我不想将其保存在数据库或缓存中。

If you just store key value pairs java already has api for this purpose. 如果仅存储键值对,则Java已经具有用于此目的的api。

You can use preferences API to store key value pairs. 您可以使用首选项API来存储键值对。

https://www.javaworld.com/article/2071328/the-preferences-api.html https://www.javaworld.com/article/2071328/the-preferences-api.html

If you have lot of entries better use Database. 如果条目很多,最好使用数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM