Describe the bug Spring Cloud Version: 2021.0.1

I'm using the composite in my spring cloud config server configuration as below:

spring:
  application:
    name: configserver
  cloud:
    config:
      server:
        prefix: "springconfig"
        health:
          enabled: false
        fail-on-composite-error: false
        git:
          timeout: 5
          strict-host-key-checking: false
        composite:
          - type: git
            uri: https://gitlab.com/test/configuration/{application}.git
            username: configserver
            password: configserver
            default-label: main
          - type: git
            uri: https://bitbucket.com/test/configuration/{application}.git
            username: configserver
            password: configserver
            default-label: master

Since I set the flag fail-on-composite-error: false , I expect that if a repo doesn't exist in butbucket it will not fail. It works for the findOne() method but it doesn't work for the getLocations(), which is wrong in my opnion.

As a workaround I created a FailoverSearchPathCompositeEnvironmentRepository class that applies the same logic used by findOne(). The code is as below:

package com.mytaxi.configserver.resource;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.config.server.environment.CompositeEnvironmentRepository;
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
import org.springframework.cloud.config.server.environment.RepositoryException;
import org.springframework.cloud.config.server.environment.SearchPathLocator;

@Slf4j
public class FailoverSearchPathCompositeEnvironmentRepository extends CompositeEnvironmentRepository
    implements SearchPathLocator
{
    private boolean failOnError;


    public FailoverSearchPathCompositeEnvironmentRepository(List<EnvironmentRepository> environmentRepositories, boolean failOnError)
    {
        super(environmentRepositories, failOnError);
        this.failOnError = failOnError;
    }


    @Override
    public Locations getLocations(String application, String profile, String label)
    {
        List<String> locations = new ArrayList<>();
        for (EnvironmentRepository repo : this.environmentRepositories)
        {
            if (repo instanceof SearchPathLocator)
            {
                try
                {
                    locations.addAll(Arrays.asList(((SearchPathLocator) repo).getLocations(application, profile, label).getLocations()));
                }
                catch (RepositoryException ex)
                {
                    if (failOnError)
                    {
                        throw ex;
                    }
                    else
                    {
                        log.info("Error finding locations for " + repo, ex);
                    }
                }
            }
        }
        return new Locations(application, profile, label, null, locations.toArray(new String[locations.size()]));
    }
}

If no location is found, an empty list is returned and a 404 is replied to the request later.

Let me know if this is a good implementation and I would be happy to provide a PR.

Comment From: ryanjbaxter

Yes please create a PR

Comment From: spring-cloud-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: sergioasantiago

ok, I will provide a PR soon.

Comment From: spencergibb

Closed via #2191