|
32 | 32 | import org.apache.commons.logging.Log;
|
33 | 33 | import org.apache.commons.logging.LogFactory;
|
34 | 34 |
|
| 35 | +import org.springframework.beans.BeansException; |
35 | 36 | import org.springframework.beans.CachedIntrospectionResults;
|
36 | 37 | import org.springframework.beans.factory.config.BeanDefinition;
|
| 38 | +import org.springframework.beans.factory.config.BeanFactoryPostProcessor; |
37 | 39 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
38 | 40 | import org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader;
|
39 | 41 | import org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory;
|
|
56 | 58 | import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
57 | 59 | import org.springframework.context.annotation.AnnotationConfigUtils;
|
58 | 60 | import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
|
| 61 | +import org.springframework.context.annotation.ConfigurationClassPostProcessor; |
59 | 62 | import org.springframework.context.support.AbstractApplicationContext;
|
60 | 63 | import org.springframework.context.support.GenericApplicationContext;
|
61 | 64 | import org.springframework.core.GenericTypeResolver;
|
@@ -397,6 +400,7 @@ private void prepareContext(DefaultBootstrapContext bootstrapContext, Configurab
|
397 | 400 | if (this.lazyInitialization) {
|
398 | 401 | context.addBeanFactoryPostProcessor(new LazyInitializationBeanFactoryPostProcessor());
|
399 | 402 | }
|
| 403 | + context.addBeanFactoryPostProcessor(new PropertySourceOrderingBeanFactoryPostProcessor(context)); |
400 | 404 | if (!NativeDetector.inNativeImage()) {
|
401 | 405 | // Load the sources
|
402 | 406 | Set<Object> sources = getAllSources();
|
@@ -1374,4 +1378,28 @@ private static <E> Set<E> asUnmodifiableOrderedSet(Collection<E> elements) {
|
1374 | 1378 | return new LinkedHashSet<>(list);
|
1375 | 1379 | }
|
1376 | 1380 |
|
| 1381 | + /** |
| 1382 | + * {@link BeanFactoryPostProcessor} to re-order our property sources below any |
| 1383 | + * {@code @PropertySource} items added by the {@link ConfigurationClassPostProcessor}. |
| 1384 | + */ |
| 1385 | + private static class PropertySourceOrderingBeanFactoryPostProcessor implements BeanFactoryPostProcessor, Ordered { |
| 1386 | + |
| 1387 | + private final ConfigurableApplicationContext context; |
| 1388 | + |
| 1389 | + PropertySourceOrderingBeanFactoryPostProcessor(ConfigurableApplicationContext context) { |
| 1390 | + this.context = context; |
| 1391 | + } |
| 1392 | + |
| 1393 | + @Override |
| 1394 | + public int getOrder() { |
| 1395 | + return Ordered.HIGHEST_PRECEDENCE; |
| 1396 | + } |
| 1397 | + |
| 1398 | + @Override |
| 1399 | + public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { |
| 1400 | + DefaultPropertiesPropertySource.moveToEnd(this.context.getEnvironment()); |
| 1401 | + } |
| 1402 | + |
| 1403 | + } |
| 1404 | + |
1377 | 1405 | }
|
0 commit comments