i am trying to externalize the application.properties (out of the jar file) In springboot 2.5.4 standalone application (not a web application)

java -jar app-1.0.jar --spring.config.location=file:D:\config\application.properties

I am getting error

Caused by: java.io.FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist

Even setting environmental variable does not work

set SPRING_CONFIG_NAME=application
set SPRING_CONFIG_LOCATION=file:D:\config\application.properties

Hope there is some issue with springboot 2.5.4

Error Log

2023-07-12 21:34:40.984  INFO 8604 --- [           main] com.s7.SchedulerApplication              : Starting SchedulerApplication v2.1.4 using Java 11.0.16.1 on DESKTOP-6NOAC01 with PID 8604 (C:\Users\app\IdeaProjects\scheduler-app\target\scheduler-app.2.1.4.jar started by app in C:\Users\app\IdeaProjects\scheduler-app\target)
2023-07-12 21:34:41.028  INFO 8604 --- [           main] com.s7.SchedulerApplication              : No active profile set, falling back to default profiles: default
2023-07-12 21:34:41.435  WARN 8604 --- [           main] onfigReactiveWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.s7.SchedulerApplication]; nested exception is java.io.FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist
2023-07-12 21:34:41.617 ERROR 8604 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.s7.SchedulerApplication]; nested exception is java.io.FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist
        at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:189) ~[spring-context-5.3.9.jar!/:5.3.9]
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331) ~[spring-context-5.3.9.jar!/:5.3.9]
        at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:247) ~[spring-context-5.3.9.jar!/:5.3.9]
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:311) ~[spring-context-5.3.9.jar!/:5.3.9]
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:112) ~[spring-context-5.3.9.jar!/:5.3.9]
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:746) ~[spring-context-5.3.9.jar!/:5.3.9]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:564) ~[spring-context-5.3.9.jar!/:5.3.9]
        at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:64) ~[spring-boot-2.5.4.jar!/:2.5.4]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-2.5.4.jar!/:2.5.4]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[spring-boot-2.5.4.jar!/:2.5.4]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) ~[spring-boot-2.5.4.jar!/:2.5.4]
        at com.s7.SchedulerApplication.main(SchedulerApplication.java:35) ~[classes!/:2.1.4]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
        at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[scheduler-app.2.1.4.jar:2.1.4]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[scheduler-app.2.1.4.jar:2.1.4]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[scheduler-app.2.1.4.jar:2.1.4]
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) ~[scheduler-app.2.1.4.jar:2.1.4]
Caused by: java.io.FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist
        at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:187) ~[spring-core-5.3.9.jar!/:5.3.9]
        at org.springframework.core.io.support.EncodedResource.getInputStream(EncodedResource.java:159) ~[spring-core-5.3.9.jar!/:5.3.9]
        at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:110) ~[spring-core-5.3.9.jar!/:5.3.9]
        at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:81) ~[spring-core-5.3.9.jar!/:5.3.9]
        at org.springframework.core.io.support.PropertiesLoaderUtils.loadProperties(PropertiesLoaderUtils.java:67) ~[spring-core-5.3.9.jar!/:5.3.9]
        at org.springframework.core.io.support.ResourcePropertySource.<init>(ResourcePropertySource.java:67) ~[spring-core-5.3.9.jar!/:5.3.9]
        at org.springframework.core.io.support.DefaultPropertySourceFactory.createPropertySource(DefaultPropertySourceFactory.java:37) ~[spring-core-5.3.9.jar!/:5.3.9]
        at org.springframework.context.annotation.ConfigurationClassParser.processPropertySource(ConfigurationClassParser.java:463) ~[spring-context-5.3.9.jar!/:5.3.9]
        at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:280) ~[spring-context-5.3.9.jar!/:5.3.9]
        at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:250) ~[spring-context-5.3.9.jar!/:5.3.9]
        at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:199) ~[spring-context-5.3.9.jar!/:5.3.9]
        at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:304) ~[spring-context-5.3.9.jar!/:5.3.9]
        at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:250) ~[spring-context-5.3.9.jar!/:5.3.9]
        at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:207) ~[spring-context-5.3.9.jar!/:5.3.9]
        at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:175) ~[spring-context-5.3.9.jar!/:5.3.9]
        ... 19 common frames omitted

Comment From: wilkinsona

Judging by the stack trace, the problem is occurring due to @PropertySource on a @Configuration class, most probably com.s7.SchedulerApplication. The location from which it tries to load properties will be unaffected by spring.config.location so you'll need to correct your use of @PropertySource.

If you have any further questions, please follow up on Stack Overflow or Gitter. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.

Also, please note that OSS support for Spring Boot 2.5 is no longer provided. You should upgrade to Spring Boot 2.7 or later.