|
19 | 19 | import java.util.ArrayList;
|
20 | 20 | import java.util.Collections;
|
21 | 21 | import java.util.List;
|
| 22 | +import java.util.Objects; |
22 | 23 | import java.util.Set;
|
23 | 24 |
|
| 25 | +import org.springframework.aot.generate.GenerationContext; |
| 26 | +import org.springframework.aot.hint.MemberCategory; |
| 27 | +import org.springframework.aot.hint.TypeReference; |
24 | 28 | import org.springframework.beans.BeansException;
|
25 | 29 | import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
|
| 30 | +import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContribution; |
| 31 | +import org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor; |
| 32 | +import org.springframework.beans.factory.aot.BeanFactoryInitializationCode; |
26 | 33 | import org.springframework.beans.factory.config.BeanDefinition;
|
27 | 34 | import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
28 | 35 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
|
40 | 47 | * @see ServletComponentScan
|
41 | 48 | * @see ServletComponentScanRegistrar
|
42 | 49 | */
|
43 |
| -class ServletComponentRegisteringPostProcessor implements BeanFactoryPostProcessor, ApplicationContextAware { |
| 50 | +class ServletComponentRegisteringPostProcessor |
| 51 | + implements BeanFactoryPostProcessor, ApplicationContextAware, BeanFactoryInitializationAotProcessor { |
44 | 52 |
|
45 | 53 | private static final List<ServletComponentHandler> HANDLERS;
|
46 | 54 |
|
@@ -105,4 +113,29 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
|
105 | 113 | this.applicationContext = applicationContext;
|
106 | 114 | }
|
107 | 115 |
|
| 116 | + @Override |
| 117 | + public BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) { |
| 118 | + return new BeanFactoryInitializationAotContribution() { |
| 119 | + |
| 120 | + @Override |
| 121 | + public void applyTo(GenerationContext generationContext, |
| 122 | + BeanFactoryInitializationCode beanFactoryInitializationCode) { |
| 123 | + for (String beanName : beanFactory.getBeanDefinitionNames()) { |
| 124 | + BeanDefinition definition = beanFactory.getBeanDefinition(beanName); |
| 125 | + if (Objects.equals(definition.getBeanClassName(), |
| 126 | + WebListenerHandler.ServletComponentWebListenerRegistrar.class.getName())) { |
| 127 | + String listenerClassName = (String) definition.getConstructorArgumentValues() |
| 128 | + .getArgumentValue(0, String.class) |
| 129 | + .getValue(); |
| 130 | + generationContext.getRuntimeHints() |
| 131 | + .reflection() |
| 132 | + .registerType(TypeReference.of(listenerClassName), |
| 133 | + MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); |
| 134 | + } |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + }; |
| 139 | + } |
| 140 | + |
108 | 141 | }
|
0 commit comments