Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application Startup Fails For Existing, Non-Optional Config Location, Resulting In ConfigDataLocationNotFoundException #24499

mwftapi opened this issue Dec 14, 2020 · 1 comment


Copy link

@mwftapi mwftapi commented Dec 14, 2020

Since upgrading from Spring Boot 2.4.0 to Spring Boot 2.4.1 a existing, non-optional config location will stop our application from starting up by throwing a ConfigDataLocationNotFoundException: Config data location '[PATH]' cannot be found exception.

I provided a sample application for reproduction:

In this demo application a config location will be created in the users home directory under ~/additional/config/location/[CURRENT_MILLIS] and within it a dummy config file named is created.

This config location will than be registered as non-optional using the spring.config.additional-location application property upon configuring the Spring Boot application prior to its startup:

public class DemoApplication extends SpringBootServletInitializer {

  public static void main(String[] args) {
    configureApplication(new SpringApplicationBuilder()).run(args);

  protected SpringApplicationBuilder configure(
      SpringApplicationBuilder builder) {
    return configureApplication(builder);

  private static SpringApplicationBuilder configureApplication(SpringApplicationBuilder builder) {
    var additionalConfigLocation = createAdditionalConfigLocation();
    return builder.sources(DemoApplication.class).properties(
        Map.of("spring.config.additional-location", additionalConfigLocation.toString() + "/")

  private static Path createAdditionalConfigLocation() {
    var additionalConfigLocation = Path
            "/additional/config/location/" + System.currentTimeMillis());
    try {
    } catch (IOException e) {
      throw new RuntimeException(
          "Could not create additional config location at " + additionalConfigLocation.toString(),
    return additionalConfigLocation;

  private static void createDummyConfigFile(Path parent) {
    var dummyConfigFile = Path.of(parent.toAbsolutePath().toString(),
    try {
      Files.writeString(dummyConfigFile, "");
    } catch (IOException e) {
      throw new RuntimeException(
          "Could not create dummy config file at " + dummyConfigFile.toString(),

According to the latest Spring Boot Reference Documentation the optional: prefix is only required if a config location might not be existing in order to prevent receiving the ConfigDataLocationNotFoundException:

By default, when a specified config data location does not exist, Spring Boot will throw a ConfigDataLocationNotFoundException and your application will not start.

If you want to specify a location, but you don’t mind if it doesn’t always exist, you can use the optional: prefix. You can use this prefix with the spring.config.location and spring.config.additional-location properties, as well as with spring.config.import declarations.

So this above provided application should startup which it did with Spring Boot 2.4.0 but which it does no longer with Spring Boot 2.4.1 resulting in the above mentioned exception.

But as soon as we start the application with test as active profile, thus triggering the search for and parsing of the file within the newly created and added config location, the registered additional config location is being found and the application starts as expected.

I think that the commit 3dc03ac2752a06e015fc8ae7a6eba483b2cc863e could have introduced this behaviour.

Copy link

@philwebb philwebb commented Dec 15, 2020

@mwftapi Thanks for the excellent report and the sample application. Your suspicion is correct, 3dc03ac did cause the problem. I've pushed a fix which should hopefully sort it for 2.4.2. In the meantime, you could prefix your location with optional:.

@philwebb philwebb modified the milestones: 2.4.x, 2.4.2 Dec 15, 2020
philwebb added a commit that referenced this issue Dec 15, 2020
Add an additional test to ensure that empty property files do not
throw ConfigDataLocationNotFoundException exceptions.

See gh-24499
See gh-24515
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants