mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-23 09:49:01 +00:00
Merge branch '3.4.x' into 3.5.x
Closes gh-48475
This commit is contained in:
+7
-1
@@ -24,7 +24,9 @@ import javax.lang.model.element.Modifier;
|
||||
|
||||
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;
|
||||
@@ -59,7 +61,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.
|
||||
@@ -234,6 +236,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
@@ -35,6 +35,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;
|
||||
@@ -209,6 +213,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