'How to load Spring Jpa properties from a txt file

In my case, based on conditions different conditions, a txt file is created which contains the database details like database url, username, password, etc. I have to load that file to create the spring jpa database connection database.

Application is in : D:\Application
Where the said txt falls : D:\Drop\Files\ExternalProperties

How to do this ? Is it even possible ?



Solution 1:[1]

I would suggest you to use spring profiles (https://docs.spring.io/spring-boot/docs/1.2.0.M1/reference/html/boot-features-profiles.html) which allowes you to create different property / yaml etc. files for storing your properties like follows:

application-prod.properties
application-extra.properties
application-dev.properties
application-local.properties

Then you can use for example a command line param to indicate which profiles you want to use:

java -jar YOUR.jar --spring.profiles.active=prod,extra

You can use different profiles at the same time and you can also provide a standard set of properties in your application.yaml, so you only have to override the properties that change in your profile based configuration.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Patrick Wilmes