|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2022 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.
|
|
29 | 29 |
|
30 | 30 | import org.springframework.aot.generate.MethodReference;
|
31 | 31 | import org.springframework.aot.generate.MethodReference.ArgumentCodeGenerator;
|
| 32 | +import org.springframework.aot.hint.MemberCategory; |
32 | 33 | import org.springframework.aot.hint.ResourcePatternHint;
|
| 34 | +import org.springframework.aot.hint.predicate.RuntimeHintsPredicates; |
33 | 35 | import org.springframework.aot.test.generate.TestGenerationContext;
|
34 | 36 | import org.springframework.beans.BeansException;
|
35 | 37 | import org.springframework.beans.factory.InitializingBean;
|
|
50 | 52 | import org.springframework.core.Ordered;
|
51 | 53 | import org.springframework.core.env.ConfigurableEnvironment;
|
52 | 54 | import org.springframework.core.io.ResourceLoader;
|
| 55 | +import org.springframework.core.io.support.DefaultPropertySourceFactory; |
53 | 56 | import org.springframework.core.test.tools.Compiled;
|
54 | 57 | import org.springframework.core.test.tools.TestCompiler;
|
55 | 58 | import org.springframework.core.type.AnnotationMetadata;
|
@@ -291,6 +294,16 @@ void applyToWhenHasPropertySourceWithDetailsRetainsThem() {
|
291 | 294 | });
|
292 | 295 | }
|
293 | 296 |
|
| 297 | + @Test |
| 298 | + void applyToWhenHasCustomFactoryRegistersHints() { |
| 299 | + BeanFactoryInitializationAotContribution contribution = getContribution( |
| 300 | + PropertySourceWithCustomFactoryConfiguration.class); |
| 301 | + contribution.applyTo(generationContext, beanFactoryInitializationCode); |
| 302 | + assertThat(RuntimeHintsPredicates.reflection().onType(CustomPropertySourcesFactory.class) |
| 303 | + .withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)) |
| 304 | + .accepts(generationContext.getRuntimeHints()); |
| 305 | + } |
| 306 | + |
294 | 307 | @SuppressWarnings("unchecked")
|
295 | 308 | private void compile(BiConsumer<Consumer<GenericApplicationContext>, Compiled> result) {
|
296 | 309 | MethodReference methodReference = beanFactoryInitializationCode.getInitializers().get(0);
|
@@ -332,6 +345,13 @@ static class PropertySourceWithDetailsConfiguration {
|
332 | 345 |
|
333 | 346 | }
|
334 | 347 |
|
| 348 | + @Configuration(proxyBeanMethods = false) |
| 349 | + @PropertySource(value = "classpath:org/springframework/context/annotation/p1.properties", |
| 350 | + factory = CustomPropertySourcesFactory.class) |
| 351 | + static class PropertySourceWithCustomFactoryConfiguration { |
| 352 | + |
| 353 | + } |
| 354 | + |
335 | 355 | }
|
336 | 356 |
|
337 | 357 | @Nested
|
@@ -379,4 +399,8 @@ private void assertPostProcessorEntry(BeanPostProcessor postProcessor, Class<?>
|
379 | 399 | .containsExactly(entry(key.getName(), value.getName()));
|
380 | 400 | }
|
381 | 401 |
|
| 402 | + static class CustomPropertySourcesFactory extends DefaultPropertySourceFactory { |
| 403 | + |
| 404 | + } |
| 405 | + |
382 | 406 | }
|
0 commit comments