I want to read 2 properties file from external location. It needs to be loaded via command line argument.
configuration.properties - > this is a normal property file and contains public information.
secure.properties - > this contains encrypted passwords.
I am giving following commands line parameters
-Dspring.config.location=file:C:\Project\properties\configuration.properties, file:C:\Project\properties\security\dev\secure.properties
The properties for configuration.properties
are working fine. As i am not directly loading file, but rather using the property.
Here, for this encrypted file i need to pass the path and load explicitly, which is not Happening.
Also the util EncryptedPropertiesReader
is available in jar and thus can't modify it.
Here, the catch is how i need to use the secure.properties
We have a class EncryptedPropertiesReader
. And it contains a load(string path)
method.
Thus i need to pass the path of the secure.properties
file.
I.e.
String env = "dev"
Properties p = EncryptedPropertiesReader.load("security\" + env + "\secure.properties");
System.out.println(p); // null
Here, i can't give the absolute path because in different environments (Unix), I'll have different path.
Thus command line is my option and need to keep properties external too.
Here Are combinations tried by me :
Command line :
giving classpath for the secure. Properties
-Dspring.config.location=file:C:\Project\properties\configuration.properties, classpath:C:\Project\properties\security\dev\
giving
spring.config.nane
-D spring.config.name=configuration, secure - Dspring.config.location=file:C:\Project\properties\configuration.properties, file:C:\Project\properties\security\dev\secure.properties
tried changing \ to /
path of url passed
("secure.properties");
//expected to work when i load class path("/secure.properties");
//expected to work when i load class path
None of the above combination worked.
Any idea what's going wrong? Or what am i missing out?
Apologies for the long question.
This is how u can load properties from any location using environment variable
-Dspring.config.location="C:\Project\properties\", -Dsecure.properties.location="C:\Project\properties\security\dev\"
@PropertySources({
@PropertySource("file:${spring.config.location}/configuration.properties"),
@PropertySource("file:${secure.properties.location}/secure.properties")})