1
1
/*
2
- * Copyright 2002-2023 the original author or authors.
2
+ * Copyright 2002-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -507,14 +507,18 @@ public void enhanceConfigurationClasses(ConfigurableListableBeanFactory beanFact
507
507
throw new BeanDefinitionStoreException ("Cannot enhance @Configuration bean definition '" +
508
508
beanName + "' since it is not stored in an AbstractBeanDefinition subclass" );
509
509
}
510
- else if (logger .isWarnEnabled () && beanFactory .containsSingleton (beanName )) {
511
- logger .warn ("Cannot enhance @Configuration bean definition '" + beanName +
512
- "' since its singleton instance has been created too early. The typical cause " +
513
- "is a non-static @Bean method with a BeanDefinitionRegistryPostProcessor " +
514
- "return type: Consider declaring such methods as 'static' and/or marking the " +
515
- "containing configuration class as 'proxyBeanMethods=false'." );
510
+ else if (beanFactory .containsSingleton (beanName )) {
511
+ if (logger .isWarnEnabled ()) {
512
+ logger .warn ("Cannot enhance @Configuration bean definition '" + beanName +
513
+ "' since its singleton instance has been created too early. The typical cause " +
514
+ "is a non-static @Bean method with a BeanDefinitionRegistryPostProcessor " +
515
+ "return type: Consider declaring such methods as 'static' and/or marking the " +
516
+ "containing configuration class as 'proxyBeanMethods=false'." );
517
+ }
518
+ }
519
+ else {
520
+ configBeanDefs .put (beanName , abd );
516
521
}
517
- configBeanDefs .put (beanName , abd );
518
522
}
519
523
}
520
524
if (configBeanDefs .isEmpty ()) {
@@ -647,9 +651,9 @@ private Map<String, String> buildImportAwareMappings() {
647
651
}
648
652
return mappings ;
649
653
}
650
-
651
654
}
652
655
656
+
653
657
private static class PropertySourcesAotContribution implements BeanFactoryInitializationAotContribution {
654
658
655
659
private static final String ENVIRONMENT_VARIABLE = "environment" ;
@@ -761,17 +765,18 @@ private CodeBlock handleNull(@Nullable Object value, Supplier<CodeBlock> nonNull
761
765
return nonNull .get ();
762
766
}
763
767
}
764
-
765
768
}
766
769
770
+
767
771
private static class ConfigurationClassProxyBeanRegistrationCodeFragments extends BeanRegistrationCodeFragmentsDecorator {
768
772
769
773
private final RegisteredBean registeredBean ;
770
774
771
775
private final Class <?> proxyClass ;
772
776
773
- public ConfigurationClassProxyBeanRegistrationCodeFragments (BeanRegistrationCodeFragments codeFragments ,
774
- RegisteredBean registeredBean ) {
777
+ public ConfigurationClassProxyBeanRegistrationCodeFragments (
778
+ BeanRegistrationCodeFragments codeFragments , RegisteredBean registeredBean ) {
779
+
775
780
super (codeFragments );
776
781
this .registeredBean = registeredBean ;
777
782
this .proxyClass = registeredBean .getBeanType ().toClass ();
@@ -780,6 +785,7 @@ public ConfigurationClassProxyBeanRegistrationCodeFragments(BeanRegistrationCode
780
785
@ Override
781
786
public CodeBlock generateSetBeanDefinitionPropertiesCode (GenerationContext generationContext ,
782
787
BeanRegistrationCode beanRegistrationCode , RootBeanDefinition beanDefinition , Predicate <String > attributeFilter ) {
788
+
783
789
CodeBlock .Builder code = CodeBlock .builder ();
784
790
code .add (super .generateSetBeanDefinitionPropertiesCode (generationContext ,
785
791
beanRegistrationCode , beanDefinition , attributeFilter ));
@@ -790,8 +796,7 @@ public CodeBlock generateSetBeanDefinitionPropertiesCode(GenerationContext gener
790
796
791
797
@ Override
792
798
public CodeBlock generateInstanceSupplierCode (GenerationContext generationContext ,
793
- BeanRegistrationCode beanRegistrationCode ,
794
- boolean allowDirectSupplierShortcut ) {
799
+ BeanRegistrationCode beanRegistrationCode , boolean allowDirectSupplierShortcut ) {
795
800
796
801
Executable executableToUse = proxyExecutable (generationContext .getRuntimeHints (),
797
802
this .registeredBean .resolveConstructorOrFactoryMethod ());
@@ -812,7 +817,6 @@ private Executable proxyExecutable(RuntimeHints runtimeHints, Executable userExe
812
817
}
813
818
return userExecutable ;
814
819
}
815
-
816
820
}
817
821
818
822
}
0 commit comments