/*
 * Copyright 2013-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.cloud.config.server.config;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.config.server.environment.CompositeEnvironmentRepository;
import org.springframework.cloud.config.server.environment.EnvironmentRepository;
import org.springframework.cloud.config.server.environment.SearchPathCompositeEnvironmentRepository;
import org.springframework.cloud.config.server.environment.SearchPathLocator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * @author Ryan Baxter
 */
@Configuration(proxyBeanMethods = false)
@ConditionalOnMissingBean(CompositeEnvironmentRepository.class)
public class CompositeConfiguration {

	private List<EnvironmentRepository> environmentRepos = new ArrayList<>();

	private ConfigServerProperties properties;

	@Bean
	@Primary
	@ConditionalOnBean(SearchPathLocator.class)
	public SearchPathCompositeEnvironmentRepository searchPathCompositeEnvironmentRepository() {
		return new SearchPathCompositeEnvironmentRepository(this.environmentRepos, properties.isFailOnCompositeError());
	}

	@Bean
	@Primary
	@ConditionalOnMissingBean(SearchPathLocator.class)
	public CompositeEnvironmentRepository compositeEnvironmentRepository() {
		return new CompositeEnvironmentRepository(this.environmentRepos, properties.isFailOnCompositeError());
	}

	@Autowired
	public void setEnvironmentRepos(List<EnvironmentRepository> repos) {
		this.environmentRepos = repos;
	}

	@Autowired
	public void setProperties(ConfigServerProperties properties) {
		this.properties = properties;
	}

}

@@ -1645,129 +1645,8 @@
  %7B%0A%0A
-%09private List%3CEnvironmentRepository%3E environmentRepos = new ArrayList%3C%3E();%0A%0A%09private ConfigServerProperties properties;%0A%0A
 %09@Be
@@ -1785,35 +1785,236 @@
 nmentRepository(
-) %7B
+%0A%09%09%09@Autowired(required = false) List%3CEnvironmentRepository%3E environmentRepos,%0A%09%09%09ConfigServerProperties properties) %7B%0A%09%09environmentRepos = environmentRepos != null ? environmentRepos : new ArrayList%3C%3E();
 %0A%09%09return new Se
@@ -2044,37 +2044,32 @@
 nmentRepository(
-this.
 environmentRepos
@@ -2255,34 +2255,46 @@
 ory(
-) %7B%0A%09%09return new Composite
+%0A%09%09%09@Autowired(required = false) List%3C
 Envi
@@ -2314,14 +2314,10 @@
 tory
-(this.
+%3E 
 envi
@@ -2333,80 +2333,52 @@
 pos,
- properties.isFailOnCompositeError());%0A%09%7D%0A%0A%09@Autowired%0A%09public void setE
+%0A%09%09%09ConfigServerProperties properties) %7B%0A%09%09e
 nvir
@@ -2392,15 +2392,12 @@
 epos
-(List%3CE
+ = e
 nvir
@@ -2411,167 +2411,155 @@
 epos
-itory%3E repos) %7B%0A%09%09this.environmentRepos = repos;%0A%09%7D%0A%0A%09@Autowired%0A%09public void setProperties(ConfigServerProperties properties) %7B%0A%09%09this.properties = properties
+ != null ? environmentRepos : new ArrayList%3C%3E();%0A%09%09return new CompositeEnvironmentRepository(environmentRepos, properties.isFailOnCompositeError())
 ;%0A%09%7D

Fix Spring AOT circular reference. (#1968)