Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2022 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -225,7 +225,6 @@ class ConfigurationClassEnhancer {
|
|||||||
};
|
};
|
||||||
return new TransformingClassGenerator(cg, transformer);
|
return new TransformingClassGenerator(cg, transformer);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -387,11 +387,11 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Detect any custom bean name generation strategy supplied through the enclosing application context
|
// Detect any custom bean name generation strategy supplied through the enclosing application context
|
||||||
SingletonBeanRegistry sbr = null;
|
SingletonBeanRegistry singletonRegistry = null;
|
||||||
if (registry instanceof SingletonBeanRegistry _sbr) {
|
if (registry instanceof SingletonBeanRegistry sbr) {
|
||||||
sbr = _sbr;
|
singletonRegistry = sbr;
|
||||||
if (!this.localBeanNameGeneratorSet) {
|
if (!this.localBeanNameGeneratorSet) {
|
||||||
BeanNameGenerator generator = (BeanNameGenerator) sbr.getSingleton(
|
BeanNameGenerator generator = (BeanNameGenerator) singletonRegistry.getSingleton(
|
||||||
AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR);
|
AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR);
|
||||||
if (generator != null) {
|
if (generator != null) {
|
||||||
this.componentScanBeanNameGenerator = generator;
|
this.componentScanBeanNameGenerator = generator;
|
||||||
@@ -452,8 +452,8 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
|
|||||||
while (!candidates.isEmpty());
|
while (!candidates.isEmpty());
|
||||||
|
|
||||||
// Register the ImportRegistry as a bean in order to support ImportAware @Configuration classes
|
// Register the ImportRegistry as a bean in order to support ImportAware @Configuration classes
|
||||||
if (sbr != null && !sbr.containsSingleton(IMPORT_REGISTRY_BEAN_NAME)) {
|
if (singletonRegistry != null && !singletonRegistry.containsSingleton(IMPORT_REGISTRY_BEAN_NAME)) {
|
||||||
sbr.registerSingleton(IMPORT_REGISTRY_BEAN_NAME, parser.getImportRegistry());
|
singletonRegistry.registerSingleton(IMPORT_REGISTRY_BEAN_NAME, parser.getImportRegistry());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the PropertySourceDescriptors to contribute them Ahead-of-time if necessary
|
// Store the PropertySourceDescriptors to contribute them Ahead-of-time if necessary
|
||||||
@@ -552,6 +552,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public PropertyValues postProcessProperties(@Nullable PropertyValues pvs, Object bean, String beanName) {
|
public PropertyValues postProcessProperties(@Nullable PropertyValues pvs, Object bean, String beanName) {
|
||||||
// Inject the BeanFactory before AutowiredAnnotationBeanPostProcessor's
|
// Inject the BeanFactory before AutowiredAnnotationBeanPostProcessor's
|
||||||
// postProcessProperties method attempts to autowire other configuration beans.
|
// postProcessProperties method attempts to autowire other configuration beans.
|
||||||
@@ -647,9 +648,9 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
|
|||||||
}
|
}
|
||||||
return mappings;
|
return mappings;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class PropertySourcesAotContribution implements BeanFactoryInitializationAotContribution {
|
private static class PropertySourcesAotContribution implements BeanFactoryInitializationAotContribution {
|
||||||
|
|
||||||
private static final String ENVIRONMENT_VARIABLE = "environment";
|
private static final String ENVIRONMENT_VARIABLE = "environment";
|
||||||
@@ -761,17 +762,18 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
|
|||||||
return nonNull.get();
|
return nonNull.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class ConfigurationClassProxyBeanRegistrationCodeFragments extends BeanRegistrationCodeFragmentsDecorator {
|
private static class ConfigurationClassProxyBeanRegistrationCodeFragments extends BeanRegistrationCodeFragmentsDecorator {
|
||||||
|
|
||||||
private final RegisteredBean registeredBean;
|
private final RegisteredBean registeredBean;
|
||||||
|
|
||||||
private final Class<?> proxyClass;
|
private final Class<?> proxyClass;
|
||||||
|
|
||||||
public ConfigurationClassProxyBeanRegistrationCodeFragments(BeanRegistrationCodeFragments codeFragments,
|
public ConfigurationClassProxyBeanRegistrationCodeFragments(
|
||||||
RegisteredBean registeredBean) {
|
BeanRegistrationCodeFragments codeFragments, RegisteredBean registeredBean) {
|
||||||
|
|
||||||
super(codeFragments);
|
super(codeFragments);
|
||||||
this.registeredBean = registeredBean;
|
this.registeredBean = registeredBean;
|
||||||
this.proxyClass = registeredBean.getBeanType().toClass();
|
this.proxyClass = registeredBean.getBeanType().toClass();
|
||||||
@@ -780,6 +782,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
|
|||||||
@Override
|
@Override
|
||||||
public CodeBlock generateSetBeanDefinitionPropertiesCode(GenerationContext generationContext,
|
public CodeBlock generateSetBeanDefinitionPropertiesCode(GenerationContext generationContext,
|
||||||
BeanRegistrationCode beanRegistrationCode, RootBeanDefinition beanDefinition, Predicate<String> attributeFilter) {
|
BeanRegistrationCode beanRegistrationCode, RootBeanDefinition beanDefinition, Predicate<String> attributeFilter) {
|
||||||
|
|
||||||
CodeBlock.Builder code = CodeBlock.builder();
|
CodeBlock.Builder code = CodeBlock.builder();
|
||||||
code.add(super.generateSetBeanDefinitionPropertiesCode(generationContext,
|
code.add(super.generateSetBeanDefinitionPropertiesCode(generationContext,
|
||||||
beanRegistrationCode, beanDefinition, attributeFilter));
|
beanRegistrationCode, beanDefinition, attributeFilter));
|
||||||
@@ -790,8 +793,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CodeBlock generateInstanceSupplierCode(GenerationContext generationContext,
|
public CodeBlock generateInstanceSupplierCode(GenerationContext generationContext,
|
||||||
BeanRegistrationCode beanRegistrationCode,
|
BeanRegistrationCode beanRegistrationCode, boolean allowDirectSupplierShortcut) {
|
||||||
boolean allowDirectSupplierShortcut) {
|
|
||||||
|
|
||||||
Executable executableToUse = proxyExecutable(generationContext.getRuntimeHints(),
|
Executable executableToUse = proxyExecutable(generationContext.getRuntimeHints(),
|
||||||
this.registeredBean.resolveConstructorOrFactoryMethod());
|
this.registeredBean.resolveConstructorOrFactoryMethod());
|
||||||
@@ -812,7 +814,6 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
|
|||||||
}
|
}
|
||||||
return userExecutable;
|
return userExecutable;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,8 +101,8 @@ class ConfigurationClassPostProcessorAotContributionTests {
|
|||||||
initializer.accept(freshBeanFactory);
|
initializer.accept(freshBeanFactory);
|
||||||
freshContext.refresh();
|
freshContext.refresh();
|
||||||
assertThat(freshBeanFactory.getBeanPostProcessors()).filteredOn(ImportAwareAotBeanPostProcessor.class::isInstance)
|
assertThat(freshBeanFactory.getBeanPostProcessors()).filteredOn(ImportAwareAotBeanPostProcessor.class::isInstance)
|
||||||
.singleElement().satisfies(postProcessor -> assertPostProcessorEntry(postProcessor, ImportAwareConfiguration.class,
|
.singleElement().satisfies(postProcessor ->
|
||||||
ImportConfiguration.class));
|
assertPostProcessorEntry(postProcessor, ImportAwareConfiguration.class, ImportConfiguration.class));
|
||||||
freshContext.close();
|
freshContext.close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -245,6 +245,7 @@ class ConfigurationClassPostProcessorAotContributionTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
class PropertySourceTests {
|
class PropertySourceTests {
|
||||||
|
|
||||||
@@ -410,9 +411,9 @@ class ConfigurationClassPostProcessorAotContributionTests {
|
|||||||
@PropertySource("classpath:org/springframework/context/annotation/p?.properties")
|
@PropertySource("classpath:org/springframework/context/annotation/p?.properties")
|
||||||
static class PropertySourceWithWildcardLocationPatternConfiguration {
|
static class PropertySourceWithWildcardLocationPatternConfiguration {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
class ConfigurationClassProxyTests {
|
class ConfigurationClassProxyTests {
|
||||||
|
|
||||||
@@ -432,15 +433,14 @@ class ConfigurationClassPostProcessorAotContributionTests {
|
|||||||
getRegisteredBean(CglibConfiguration.class))).isNotNull();
|
getRegisteredBean(CglibConfiguration.class))).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private RegisteredBean getRegisteredBean(Class<?> bean) {
|
private RegisteredBean getRegisteredBean(Class<?> bean) {
|
||||||
this.beanFactory.registerBeanDefinition("test", new RootBeanDefinition(bean));
|
this.beanFactory.registerBeanDefinition("test", new RootBeanDefinition(bean));
|
||||||
this.processor.postProcessBeanFactory(this.beanFactory);
|
this.processor.postProcessBeanFactory(this.beanFactory);
|
||||||
return RegisteredBean.of(this.beanFactory, "test");
|
return RegisteredBean.of(this.beanFactory, "test");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private BeanFactoryInitializationAotContribution getContribution(Class<?>... types) {
|
private BeanFactoryInitializationAotContribution getContribution(Class<?>... types) {
|
||||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||||
@@ -458,8 +458,8 @@ class ConfigurationClassPostProcessorAotContributionTests {
|
|||||||
.containsExactly(entry(key.getName(), value.getName()));
|
.containsExactly(entry(key.getName(), value.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
static class CustomPropertySourcesFactory extends DefaultPropertySourceFactory {
|
|
||||||
|
|
||||||
|
static class CustomPropertySourcesFactory extends DefaultPropertySourceFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ public class ReflectUtils {
|
|||||||
Throwable throwable = null;
|
Throwable throwable = null;
|
||||||
try {
|
try {
|
||||||
classLoaderDefineClass = ClassLoader.class.getDeclaredMethod("defineClass",
|
classLoaderDefineClass = ClassLoader.class.getDeclaredMethod("defineClass",
|
||||||
String.class, byte[].class, Integer.TYPE, Integer.TYPE, ProtectionDomain.class);
|
String.class, byte[].class, Integer.TYPE, Integer.TYPE, ProtectionDomain.class);
|
||||||
}
|
}
|
||||||
catch (Throwable t) {
|
catch (Throwable t) {
|
||||||
classLoaderDefineClass = null;
|
classLoaderDefineClass = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user