|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2021 the original author or authors. |
| 2 | + * Copyright 2002-2023 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
32 | 32 | import org.springframework.beans.factory.BeanDefinitionStoreException;
|
33 | 33 | import org.springframework.beans.factory.FactoryBean;
|
34 | 34 | import org.springframework.beans.testfixture.beans.TestBean;
|
| 35 | +import org.springframework.context.ApplicationContext; |
35 | 36 | import org.springframework.context.ConfigurableApplicationContext;
|
36 | 37 | import org.springframework.core.annotation.AliasFor;
|
37 | 38 | import org.springframework.core.env.Environment;
|
@@ -239,6 +240,14 @@ void withRepeatedPropertySourcesOnComposedAnnotation() {
|
239 | 240 | }
|
240 | 241 | }
|
241 | 242 |
|
| 243 | + @Test |
| 244 | + void multipleComposedPropertySourceAnnotations() { // gh-30941 |
| 245 | + ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(MultipleComposedAnnotationsConfig.class); |
| 246 | + ctx.getBean(MultipleComposedAnnotationsConfig.class); |
| 247 | + assertEnvironmentContainsProperties(ctx, "from.p1", "from.p2", "from.p3", "from.p4", "from.p5"); |
| 248 | + ctx.close(); |
| 249 | + } |
| 250 | + |
242 | 251 | @Test
|
243 | 252 | void withNamedPropertySources() {
|
244 | 253 | AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithNamedPropertySources.class);
|
@@ -305,6 +314,17 @@ void orderingDoesntReplaceExisting() throws Exception {
|
305 | 314 | }
|
306 | 315 |
|
307 | 316 |
|
| 317 | + private static void assertEnvironmentContainsProperties(ApplicationContext ctx, String... names) { |
| 318 | + for (String name : names) { |
| 319 | + assertThat(ctx.getEnvironment().containsProperty(name)).as("environment contains property " + name).isTrue(); |
| 320 | + } |
| 321 | + } |
| 322 | + |
| 323 | + private static void assertEnvironmentContainsProperty(ApplicationContext ctx, String name) { |
| 324 | + assertThat(ctx.getEnvironment().containsProperty(name)).as("environment contains property " + name).isTrue(); |
| 325 | + } |
| 326 | + |
| 327 | + |
308 | 328 | @Configuration
|
309 | 329 | @PropertySource("classpath:${unresolvable}/p1.properties")
|
310 | 330 | static class ConfigWithUnresolvablePlaceholder {
|
@@ -496,6 +516,28 @@ static class ConfigWithRepeatedPropertySourceAnnotations {
|
496 | 516 | static class ConfigWithRepeatedPropertySourceAnnotationsOnComposedAnnotation {
|
497 | 517 | }
|
498 | 518 |
|
| 519 | + @Retention(RetentionPolicy.RUNTIME) |
| 520 | + @PropertySource("classpath:org/springframework/context/annotation/p1.properties") |
| 521 | + @interface PropertySource1 { |
| 522 | + } |
| 523 | + |
| 524 | + @Retention(RetentionPolicy.RUNTIME) |
| 525 | + @PropertySource("classpath:org/springframework/context/annotation/p2.properties") |
| 526 | + @PropertySources({ |
| 527 | + @PropertySource("classpath:org/springframework/context/annotation/p3.properties"), |
| 528 | + }) |
| 529 | + @interface PropertySource23 { |
| 530 | + } |
| 531 | + |
| 532 | + @Configuration |
| 533 | + @PropertySource1 |
| 534 | + @PropertySource23 |
| 535 | + @PropertySources({ |
| 536 | + @PropertySource("classpath:org/springframework/context/annotation/p4.properties") |
| 537 | + }) |
| 538 | + @PropertySource("classpath:org/springframework/context/annotation/p5.properties") |
| 539 | + static class MultipleComposedAnnotationsConfig { |
| 540 | + } |
499 | 541 |
|
500 | 542 | @Configuration
|
501 | 543 | @PropertySources({
|
|
0 commit comments