mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-10-03 07:49:03 +00:00
Merge branch '3.5.x'
Closes gh-48476
This commit is contained in:
+7
-1
@@ -26,7 +26,9 @@ import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.aot.AotDetector;
|
||||
import org.springframework.aot.generate.GeneratedClass;
|
||||
import org.springframework.aot.generate.GeneratedTypeReference;
|
||||
import org.springframework.aot.generate.GenerationContext;
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.beans.BeanInstantiationException;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContribution;
|
||||
@@ -62,7 +64,7 @@ import org.springframework.util.ObjectUtils;
|
||||
*/
|
||||
public class EnvironmentPostProcessorApplicationListener implements SmartApplicationListener, Ordered {
|
||||
|
||||
private static final String AOT_FEATURE_NAME = "EnvironmentPostProcessor";
|
||||
static final String AOT_FEATURE_NAME = "EnvironmentPostProcessor";
|
||||
|
||||
/**
|
||||
* The default order for the processor.
|
||||
@@ -238,6 +240,10 @@ public class EnvironmentPostProcessorApplicationListener implements SmartApplica
|
||||
method.addParameter(SpringApplication.class, "application");
|
||||
method.addCode(generateActiveProfilesInitializeCode());
|
||||
});
|
||||
generationContext.getRuntimeHints()
|
||||
.reflection()
|
||||
.registerType(GeneratedTypeReference.of(generatedClass.getName()),
|
||||
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS);
|
||||
}
|
||||
|
||||
private CodeBlock generateActiveProfilesInitializeCode() {
|
||||
|
||||
+22
@@ -36,6 +36,10 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.aot.AotDetector;
|
||||
import org.springframework.aot.generate.GenerationContext;
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.TypeReference;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.aot.test.generate.TestGenerationContext;
|
||||
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContribution;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
@@ -211,6 +215,24 @@ class EnvironmentPostProcessorApplicationListenerTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void aotContributionRegistersReflectionHints() {
|
||||
GenericApplicationContext applicationContext = new GenericApplicationContext();
|
||||
ConfigurableEnvironment environment = new StandardEnvironment();
|
||||
environment.setActiveProfiles("one", "two");
|
||||
applicationContext.getBeanFactory().registerSingleton("environment", environment);
|
||||
BeanFactoryInitializationAotContribution aotContribution = new EnvironmentBeanFactoryInitializationAotProcessor()
|
||||
.processAheadOfTime(applicationContext.getBeanFactory());
|
||||
assertThat(aotContribution).isNotNull();
|
||||
GenerationContext generationContext = new TestGenerationContext();
|
||||
aotContribution.applyTo(generationContext, null);
|
||||
assertThat(RuntimeHintsPredicates.reflection()
|
||||
.onType(TypeReference.of(TestGenerationContext.TEST_TARGET + "__"
|
||||
+ EnvironmentPostProcessorApplicationListener.AOT_FEATURE_NAME))
|
||||
.withMemberCategory(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS))
|
||||
.accepts(generationContext.getRuntimeHints());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUseAotEnvironmentPostProcessor() {
|
||||
SpringApplication application = new SpringApplication(ExampleAotProcessedApp.class);
|
||||
|
||||
Reference in New Issue
Block a user