Browse Source

Polish AOT support

pull/28896/head
Sam Brannen 3 years ago
parent
commit
ad99add429
  1. 21
      spring-beans/src/main/java/org/springframework/beans/factory/aot/AotServices.java
  2. 3
      spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanFactoryInitializationAotContribution.java
  3. 13
      spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanFactoryInitializationAotProcessor.java
  4. 4
      spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanFactoryInitializationCode.java
  5. 2
      spring-context/src/main/java/org/springframework/context/aot/ApplicationContextAotInitializer.java

21
spring-beans/src/main/java/org/springframework/beans/factory/aot/AotServices.java

@ -71,8 +71,7 @@ public final class AotServices<T> implements Iterable<T> { @@ -71,8 +71,7 @@ public final class AotServices<T> implements Iterable<T> {
return Collections.unmodifiableList(services);
}
private Map<T, Source> collectSources(Collection<T> loaded,
Collection<T> beans) {
private Map<T, Source> collectSources(Collection<T> loaded, Collection<T> beans) {
Map<T, Source> sources = new IdentityHashMap<>();
loaded.forEach(service -> sources.put(service, Source.SPRING_FACTORIES_LOADER));
beans.forEach(service -> sources.put(service, Source.BEAN_FACTORY));
@ -80,7 +79,7 @@ public final class AotServices<T> implements Iterable<T> { @@ -80,7 +79,7 @@ public final class AotServices<T> implements Iterable<T> {
}
/**
* Return a new {@link Loader} that will obtain AOT services from
* Create a new {@link Loader} that will obtain AOT services from
* {@value #FACTORIES_RESOURCE_LOCATION}.
* @return a new {@link Loader} instance
*/
@ -89,7 +88,7 @@ public final class AotServices<T> implements Iterable<T> { @@ -89,7 +88,7 @@ public final class AotServices<T> implements Iterable<T> {
}
/**
* Return a new {@link Loader} that will obtain AOT services from
* Create a new {@link Loader} that will obtain AOT services from
* {@value #FACTORIES_RESOURCE_LOCATION}.
* @param classLoader the class loader used to load the factories resource
* @return a new {@link Loader} instance
@ -99,7 +98,7 @@ public final class AotServices<T> implements Iterable<T> { @@ -99,7 +98,7 @@ public final class AotServices<T> implements Iterable<T> {
}
/**
* Return a new {@link Loader} that will obtain AOT services from the given
* Create a new {@link Loader} that will obtain AOT services from the given
* {@link SpringFactoriesLoader}.
* @param springFactoriesLoader the spring factories loader
* @return a new {@link Loader} instance
@ -110,20 +109,20 @@ public final class AotServices<T> implements Iterable<T> { @@ -110,20 +109,20 @@ public final class AotServices<T> implements Iterable<T> {
}
/**
* Return a new {@link Loader} that will obtain AOT services from
* Create a new {@link Loader} that will obtain AOT services from
* {@value #FACTORIES_RESOURCE_LOCATION} as well as the given
* {@link ListableBeanFactory}.
* @param beanFactory the bean factory
* @return a new {@link Loader} instance
*/
public static Loader factoriesAndBeans(ListableBeanFactory beanFactory) {
ClassLoader classLoader = (beanFactory instanceof ConfigurableBeanFactory configurableBeanFactory)
? configurableBeanFactory.getBeanClassLoader() : null;
ClassLoader classLoader = (beanFactory instanceof ConfigurableBeanFactory configurableBeanFactory ?
configurableBeanFactory.getBeanClassLoader() : null);
return factoriesAndBeans(getSpringFactoriesLoader(classLoader), beanFactory);
}
/**
* Return a new {@link Loader} that will obtain AOT services from the given
* Create a new {@link Loader} that will obtain AOT services from the given
* {@link SpringFactoriesLoader} and {@link ListableBeanFactory}.
* @param springFactoriesLoader the spring factories loader
* @param beanFactory the bean factory
@ -163,7 +162,7 @@ public final class AotServices<T> implements Iterable<T> { @@ -163,7 +162,7 @@ public final class AotServices<T> implements Iterable<T> {
}
/**
* Return the AOT services that was loaded for the given bean name.
* Find the AOT service that was loaded for the given bean name.
* @param beanName the bean name
* @return the AOT service or {@code null}
*/
@ -173,7 +172,7 @@ public final class AotServices<T> implements Iterable<T> { @@ -173,7 +172,7 @@ public final class AotServices<T> implements Iterable<T> {
}
/**
* Return the source of the given service.
* Get the source of the given service.
* @param service the service instance
* @return the source of the service
*/

3
spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanFactoryInitializationAotContribution.java

@ -34,8 +34,7 @@ import org.springframework.aot.generate.GenerationContext; @@ -34,8 +34,7 @@ import org.springframework.aot.generate.GenerationContext;
public interface BeanFactoryInitializationAotContribution {
/**
* Apply this contribution to the given
* {@link BeanFactoryInitializationCode}.
* Apply this contribution to the given {@link BeanFactoryInitializationCode}.
* @param generationContext the active generation context
* @param beanFactoryInitializationCode the bean factory initialization code
*/

13
spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanFactoryInitializationAotProcessor.java

@ -28,10 +28,9 @@ import org.springframework.lang.Nullable; @@ -28,10 +28,9 @@ import org.springframework.lang.Nullable;
* registered in a {@value AotServices#FACTORIES_RESOURCE_LOCATION} resource or
* as a bean.
*
* <p>
* Note: Using this interface on a registered bean will cause the bean
* <p>Note: Using this interface on a registered bean will cause the bean
* <em>and</em> all of its dependencies to be initialized during AOT processing.
* We generally recommend that interface is only used with infrastructure beans
* We generally recommend that this interface is only used with infrastructure beans
* such as {@link BeanFactoryPostProcessor} which have limited dependencies and
* are already initialized early in the bean factory lifecycle.
*
@ -46,14 +45,12 @@ public interface BeanFactoryInitializationAotProcessor { @@ -46,14 +45,12 @@ public interface BeanFactoryInitializationAotProcessor {
/**
* Process the given {@link ConfigurableListableBeanFactory} instance
* ahead-of-time and return a contribution or {@code null}.
* <p>
* Processors are free to use any techniques they like to analyze the given
* <p>Processors are free to use any techniques they like to analyze the given
* bean factory. Most typically use reflection to find fields or methods to
* use in the contribution. Contributions typically generate source code or
* resource files that can be used when the AOT optimized application runs.
* <p>
* If the given bean factory does not contain anything that is relevant to
* the processor, it should return a {@code null} contribution.
* <p>If the given bean factory does not contain anything that is relevant to
* the processor, this method should return a {@code null} contribution.
* @param beanFactory the bean factory to process
* @return a {@link BeanFactoryInitializationAotContribution} or {@code null}
*/

4
spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanFactoryInitializationCode.java

@ -30,12 +30,12 @@ import org.springframework.aot.generate.MethodReference; @@ -30,12 +30,12 @@ import org.springframework.aot.generate.MethodReference;
public interface BeanFactoryInitializationCode {
/**
* The recommended variable name to used referring to the bean factory.
* The recommended variable name to use to refer to the bean factory.
*/
String BEAN_FACTORY_VARIABLE = "beanFactory";
/**
* Return the {@link GeneratedMethods} being used by the Initializing code.
* Get the {@link GeneratedMethods} used by the initializing code.
* @return the generated methods
*/
GeneratedMethods getMethods();

2
spring-context/src/main/java/org/springframework/context/aot/ApplicationContextAotInitializer.java

@ -37,7 +37,7 @@ public class ApplicationContextAotInitializer { @@ -37,7 +37,7 @@ public class ApplicationContextAotInitializer {
/**
* Initialize the specified application context using the specified
* {@link ApplicationContextInitializer} class names. Each class name is
* {@link ApplicationContextInitializer} class names. Each class is
* expected to have a default constructor.
* @param context the context to initialize
* @param initializerClassNames the application context initializer class names

Loading…
Cancel
Save