Allow bean factory initialization to have a more flexible signature

This commit allows bean factory initialization to use a more flexible
signature than just consuming the DefaultListableBeanFactory. The
environment and the resource loader can now be specified if necessary.

See gh-29005
This commit is contained in:
Stephane Nicoll
2022-09-07 16:04:29 +02:00
parent ae706f3954
commit 2b45fd4388
3 changed files with 125 additions and 7 deletions

View File

@@ -24,6 +24,7 @@ import org.springframework.aot.generate.MethodReference;
* perform bean factory initialization.
*
* @author Phillip Webb
* @author Stephane Nicoll
* @since 6.0
* @see BeanFactoryInitializationAotContribution
*/
@@ -41,10 +42,16 @@ public interface BeanFactoryInitializationCode {
GeneratedMethods getMethods();
/**
* Add an initializer method call.
* @param methodReference a reference to the initialize method to call. The
* referenced method must have the same functional signature as
* {@code Consumer<DefaultListableBeanFactory>}.
* Add an initializer method call. An initializer can use a flexible signature,
* using any of the following:
* <ul>
* <li>{@code DefaultListableBeanFactory}, or {@code ConfigurableListableBeanFactory}
* to use the bean factory.</li>
* <li>{@code ConfigurableEnvironment} or {@code Environment} to access the
* environment.</li>
* <li>{@code ResourceLoader} to load resources.</li>
* </ul>
* @param methodReference a reference to the initialize method to call.
*/
void addInitializer(MethodReference methodReference);