Spring Boot auto configuration was recently changed with version 2.7 and most of the settings deprecated with version 3.0 (you can find details here). Also, they introduced new annotation for auto configuration classes which is @AutoConfiguration. I couldn't understand default settings of the annotation which stated below:
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Configuration(proxyBeanMethods = false)
@AutoConfigureBefore
@AutoConfigureAfter
public @interface AutoConfiguration {
}
Why they enforced users to inherit proxyBeanMethods = false, @AutoConfigureBefore and @AutoConfigureAfter?
The reason we default to
proxyBeanMethods=falseis because we think that is the most sensible default for auto-configuration classes. It means that less processing time is required when starting the application.Say you have a configuration like this:
In this case Spring must dynamically create CGLIB subclass of
MyConfigurationjust to ensure that any call tomyBean2()actually delegates to theBeanFactory.This means that additional bytecode needs to be generated and loaded as the application starts.
If you rewrite the configuration as follows:
Not only do you save resources, but the code is more honest about what it is actually doing.
If you really really want to continue to use proxy classes you can continue to use
@Configuration. Classes loaded from entries in theMETA-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.importsfile do not actually need to be annotated with@AutoConfiguration.