1

I have a project with demoApp which has application.properties in folder

/src/main/resources

Now I want to store the application.properties in some location like :

C:\Users\lenovo\Desktop\externalResource\resources

I have tried some work like setting the config location in setenv.bat file like

set spring.config.location=C:\Users\lenovo\Desktop\externalResource\resources\

Also used to set the path in system environment as :

CONF_DIR =  C:\Users\lenovo\Desktop\externalResource\resources\

and try to access in code like :

   public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
    PropertySourcesPlaceholderConfigurer propertySource = new PropertySourcesPlaceholderConfigurer();
    ClassPathResource[] resource = new ClassPathResource[]{new ClassPathResource("file:${CONF_DIR}/application-external.properties")};
    propertySource.setLocations(resource);
    propertySource.setIgnoreUnresolvablePlaceholders(true);
    return propertySource;
}

None of the previous solution worked for me which were provided in the previous question. What thing I am missing here?

Sudip Bolakhe
  • 513
  • 5
  • 16

1 Answers1

0

Here you can find some tips about use external config files: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

For example:

$ java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties

Update:

Please, check if this snippet can help you: https://stackoverflow.com/a/44442786/974966

Also, if you want to keep your current implementation, try to read the ${CONF_DIR} before use it: final String confDir = System.getenv("CONF_DIR")

And then,

ClassPathResource[] resource = new ClassPathResource[]{new ClassPathResource("file:"+ confDir +"/application-external.properties")};