简体   繁体   中英

Use external configuration for deployed war

For security reasons, I have to store the passwords in an external application.yml (outside the war ), which should be loaded by the deployed war on runtime.

Do you know where do I have to place the external configuration file? Do I have to configure some properties?

Thank you in advance!

I assume you have a war file which contains a spring-boot application, in general there are more options to manage your properties, check out the document here: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

I will recommend you 2 different approaches:

  1. Set your properties as environment variables, there is much easier way to manage properties if you have a separate container for your application.
  2. Otherwise spring provides you the possibility to override properties using commandline argument, you can do something like: java -jar myproject.war --spring.config.location=file:/default.properties

If you want to store confidential data in the server, then please add <Environment> to the context.xml file of tomcat server. Example: <Environment name="user.password" value="XXXXXXXX" type="java.lang.String" override="false"/> . You can access them as properties in spring context.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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