Support multiple @ImportRuntimeHints in the type hierarchy
This commit copies and adapts the logic from DefaultListableBeanFactory#findMergedAnnotationOnBean private method to make it suitable for returning multiple annotations found in the type hierarchy in order to support this use case with @ImportRuntimeHints. Closes gh-29361
This commit is contained in:
@@ -46,6 +46,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
* Tests for {@link RuntimeHintsBeanFactoryInitializationAotProcessor}.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
class RuntimeHintsBeanFactoryInitializationAotProcessorTests {
|
||||
|
||||
@@ -68,6 +69,15 @@ class RuntimeHintsBeanFactoryInitializationAotProcessorTests {
|
||||
assertThatSampleRegistrarContributed();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldProcessRegistrarsOnInheritedConfiguration() {
|
||||
GenericApplicationContext applicationContext = createApplicationContext(
|
||||
ExtendedConfigurationWithHints.class);
|
||||
this.generator.processAheadOfTime(applicationContext,
|
||||
this.generationContext);
|
||||
assertThatInheritedSampleRegistrarContributed();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldProcessRegistrarOnBeanMethod() {
|
||||
GenericApplicationContext applicationContext = createApplicationContext(
|
||||
@@ -121,6 +131,14 @@ class RuntimeHintsBeanFactoryInitializationAotProcessorTests {
|
||||
.anyMatch(bundleHint -> "sample".equals(bundleHint.getBaseName()));
|
||||
}
|
||||
|
||||
private void assertThatInheritedSampleRegistrarContributed() {
|
||||
assertThatSampleRegistrarContributed();
|
||||
Stream<ResourceBundleHint> bundleHints = this.generationContext.getRuntimeHints()
|
||||
.resources().resourceBundleHints();
|
||||
assertThat(bundleHints)
|
||||
.anyMatch(bundleHint -> "extendedSample".equals(bundleHint.getBaseName()));
|
||||
}
|
||||
|
||||
private GenericApplicationContext createApplicationContext(
|
||||
Class<?>... configClasses) {
|
||||
GenericApplicationContext applicationContext = new GenericApplicationContext();
|
||||
@@ -138,6 +156,10 @@ class RuntimeHintsBeanFactoryInitializationAotProcessorTests {
|
||||
static class ConfigurationWithHints {
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ImportRuntimeHints(ExtendedSampleRuntimeHintsRegistrar.class)
|
||||
static class ExtendedConfigurationWithHints extends ConfigurationWithHints {
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class ConfigurationWithBeanDeclaringHints {
|
||||
@@ -159,6 +181,15 @@ class RuntimeHintsBeanFactoryInitializationAotProcessorTests {
|
||||
|
||||
}
|
||||
|
||||
public static class ExtendedSampleRuntimeHintsRegistrar implements RuntimeHintsRegistrar {
|
||||
|
||||
@Override
|
||||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||
hints.resources().registerResourceBundle("extendedSample");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@ImportRuntimeHints(IncrementalRuntimeHintsRegistrar.class)
|
||||
static class ConfigurationWithIncrementalHints {
|
||||
|
||||
Reference in New Issue
Block a user