Search code examples
javaspringspring-bootjarproperties

Spring Boot External properties outside of jar


I am creating a Spring Boot application and i faced this problem.
I have my application.properties in recource folder but i also need external.properties file outside of jar to configure properties such like:
name,
password,
etc.
I want to have external.properties file outside of jar and inside resources folder for testing while developing.
I tried creating configuration file like this:

@Configuration
 @PropertySource("classpath:" + SpringConfiguration.EXTERNALIZED_PROPERTIES)
 @PropertySource(value = "file:./" + 
 SpringConfiguration.EXTERNALIZED_PROPERTIES, ignoreResourceNotFound = true)
 public class SpringConfiguration {
       static final String EXTERNALIZED_PROPERTIES = "external.properties";
 }

But it still reads properties from resource folder. How can i make it read from outside of jar?


Solution

  • The solution was to delete external.properties and configuration file. And instead of using it put all properties to application.properties. And put application.properties to folder with jar. Spring automatically prioritizes this property file over the property file inside jar.