简体   繁体   中英

`spring.config.location` is ignored

Fairly straight forward. I have a configuration file:

# ls -la /etc/my-application
-rwxr-xr-x 1 root root 18 May  3 04:24 /etc/my-application
# cat /etc/my-application
server.port=12345

I run my application as a follows:

java org.springframework.boot.loader.JarLauncher --spring.config.location="file:///etc/my-application"

And logging indicates the setting is visible to the application:

04:28:16.919 [main] WARNING CONFIG- [--spring.config.location=file:///etc/my-application]

But my settings are ignored:

Tomcat initialized with port(s): 8080 (http)

The following yields the same outcome:

java org.springframework.boot.loader.JarLauncher --spring.config.location="file://etc/my-application"

So does:

java org.springframework.boot.loader.JarLauncher --spring.config.location="file:/etc/my-application"

This doesn't work either, the arguments don't come through as well:

java -Dspring.config.location="file:///etc/my-application" org.springframework.boot.loader.JarLauncher
...
... 04:36:53.979 [main] WARNING CONFIG - []

Curiously enough if I specify the setting directly, it works:

java org.springframework.boot.loader.JarLauncher --server.port=12345
...
... Tomcat initialized with port(s): 12345 (http)

Where am I going wrong with this? Tearing my hair out over this one!

Is '/etc/my-application' a directory? If yes, you are missing a trailing slash in all your tries. You definitely need that.

eg /etc/my-application/

The winning combination turned out be:

java org.springframework.boot.loader.JarLauncher --spring.config.location=file:///etc/resources-master-server.properties

The key point here is that extension matters . Spring appears to determine what the settings file is by the extension, rather than the contents of the file and without the extension it didn't seem to know what to do with the properties file.

Thankyou to those who chipped in for their help and suggestions, Sameer twigged me as to what the issue may be.

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