Browse Source

Merge branch '6.0.x'

pull/30891/head
Stephane Nicoll 3 years ago
parent
commit
f73f1e0687
  1. 2
      spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanInstanceSupplier.java
  2. 3
      spring-beans/src/main/java/org/springframework/beans/factory/aot/InstanceSupplierCodeGenerator.java
  3. 4
      spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanInstanceSupplierTests.java
  4. 4
      spring-beans/src/test/java/org/springframework/beans/factory/aot/InstanceSupplierCodeGeneratorTests.java

2
spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanInstanceSupplier.java

@ -173,7 +173,9 @@ public final class BeanInstanceSupplier<T> extends AutowiredElementResolver impl @@ -173,7 +173,9 @@ public final class BeanInstanceSupplier<T> extends AutowiredElementResolver impl
* {@code generator} supplier to instantiate the underlying bean.
* @param generator a {@link ThrowingSupplier} to instantiate the underlying bean
* @return a new {@link BeanInstanceSupplier} instance with the specified generator
* @deprecated in favor of {@link #withGenerator(ThrowingFunction)}
*/
@Deprecated(since = "6.0.11", forRemoval = true)
public BeanInstanceSupplier<T> withGenerator(ThrowingSupplier<T> generator) {
Assert.notNull(generator, "'generator' must not be null");
return new BeanInstanceSupplier<>(this.lookup,

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

@ -233,7 +233,8 @@ class InstanceSupplierCodeGenerator { @@ -233,7 +233,8 @@ class InstanceSupplierCodeGenerator {
CodeBlock.Builder code = CodeBlock.builder();
code.add("$T.<$T>forFactoryMethod($T.class, $S)", BeanInstanceSupplier.class,
suppliedType, declaringClass, factoryMethod.getName());
code.add(".withGenerator($T::$L)", declaringClass, factoryMethod.getName());
code.add(".withGenerator(($L) -> $T.$L())", REGISTERED_BEAN_PARAMETER_NAME,
declaringClass, factoryMethod.getName());
return code.build();
}

4
spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanInstanceSupplierTests.java

@ -186,6 +186,8 @@ class BeanInstanceSupplierTests { @@ -186,6 +186,8 @@ class BeanInstanceSupplierTests {
}
@Test
@Deprecated
@SuppressWarnings("removal")
void withGeneratorWhenSupplierIsNullThrowsException() {
BeanInstanceSupplier<Object> resolver = BeanInstanceSupplier
.forConstructor();
@ -245,6 +247,8 @@ class BeanInstanceSupplierTests { @@ -245,6 +247,8 @@ class BeanInstanceSupplierTests {
}
@Test
@Deprecated
@SuppressWarnings("removal")
void getWithGeneratorCallsSupplier() throws Exception {
BeanRegistrar registrar = new BeanRegistrar(SingleArgConstructor.class);
this.beanFactory.registerSingleton("one", "1");

4
spring-beans/src/test/java/org/springframework/beans/factory/aot/InstanceSupplierCodeGeneratorTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -223,7 +223,7 @@ class InstanceSupplierCodeGeneratorTests { @@ -223,7 +223,7 @@ class InstanceSupplierCodeGeneratorTests {
assertThat(bean).isInstanceOf(Integer.class);
assertThat(bean).isEqualTo(42);
assertThat(compiled.getSourceFile())
.contains("SimpleConfiguration::integerBean");
.contains("(registeredBean) -> SimpleConfiguration.integerBean()");
});
assertThat(getReflectionHints().getTypeHint(SimpleConfiguration.class))
.satisfies(hasMethodWithMode(ExecutableMode.INTROSPECT));

Loading…
Cancel
Save