How @Configuration(proxyBeanMethods=false) Supercharges Spring Boot Startup Speed
This article explains how using @Configuration(proxyBeanMethods=false) in Spring Boot 2.2 reduces bean proxy generation, cuts startup time by several seconds, and provides step‑by‑step code examples, performance logs, and best‑practice recommendations for modern Java microservices.
Spring Boot 2.2 dramatically improves microservice startup speed, and this article reveals how to leverage
@Configuration(proxyBeanMethods=false)for further gains.
Background
Spring Boot’s official issue "Use @Configuration(proxyBeanMethods=false) wherever possible" was opened on May 3, 2017, discussing the progress of this feature and its impact on startup time.
Default behavior:
<code>2017-05-02 22:09:59.733 INFO 93667 --- [ main] s.a.ui.SampleActuatorUiApplication : Started SampleActuatorUiApplication in 3.136 seconds (JVM running for 3.491)
2017-05-02 22:10:19.132 INFO 93734 --- [ main] s.a.ui.SampleActuatorUiApplication : Started SampleActuatorUiApplication in 3.156 seconds (JVM running for 3.507)
2017-05-02 22:10:27.976 INFO 93795 --- [ main] s.a.ui.SampleActuatorUiApplication : Started SampleActuatorUiApplication in 3.150 seconds (JVM running for 3.502)</code>Optimized behavior:
<code>2017-05-02 22:14:43.020 INFO 94861 --- [ main] s.a.ui.SampleActuatorUiApplication : Started SampleActuatorUiApplication in 3.123 seconds (JVM running for 3.483)
2017-05-02 22:14:55.886 INFO 94922 --- [ main] s.a.ui.SampleActuatorUiApplication : Started SampleActuatorUiApplication in 3.095 seconds (JVM running for 3.454)
2017-05-02 22:15:11.822 INFO 94989 --- [ main] s.a.ui.SampleActuatorUiApplication : Started SampleActuatorUiApplication in 2.979 seconds (JVM running for 3.342)
2017-05-02 22:17:49.842 INFO 95138 --- [ main] s.a.ui.SampleActuatorUiApplication : Started SampleActuatorUiApplication in 2.921 seconds (JVM running for 3.269)</code>A simple property change can shave several seconds off startup, especially when many
starterdependencies are used.
Now Let’s Uncover the Steps
In IntelliJ IDEA, create a Spring Boot 2.2 demo project using Spring Initializr.
Default Case
Modify DemoApplication to output the CGLIB bytecode generation directory:
<code>@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
// set CGLIB bytecode generation directory
String sourcePath = DemoApplication.class.getResource("").getFile().split("target")[0] + "gen_code";
System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, sourcePath);
SpringApplication.run(DemoApplication.class, args);
}
}
</code>Run the main method; a gen_code folder appears beside the project:
proxyBeanMethods=false
Note that the
@SpringBootApplicationannotation combines
@Configuration, which can also set
proxyBeanMethods = false:
<code>@SpringBootApplication(proxyBeanMethods = false)
public class DemoApplication {
public static void main(String[] args) {
// set CGLIB bytecode generation directory
String sourcePath = DemoApplication.class.getResource("").getFile().split("target")[0] + "gen_code";
System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, sourcePath);
SpringApplication.run(DemoApplication.class, args);
}
}
</code>Running the application again produces no
gen_codedirectory and no CGLIB generation logs, confirming that bean proxying was disabled.
Conclusion
Spring uses CGLIB to enhance beans defined in @Configuration classes; with many starter modules, this proxying adds noticeable startup time and memory overhead.
When developing with Spring Boot 2.2 (or later), set @Configuration(proxyBeanMethods = false) on auto‑configuration classes to avoid unnecessary proxy generation.
The Spring team has been promoting this setting for over two years, and it will appear in more contexts such as @Component and other auto‑configuration scenarios.
Next, we will dissect Spring’s lazy initialization feature.
<code>It is now possible to enable global lazy initialization to reduce startup time via the spring.main.lazy-initialization property. Please note that using this feature does come at a cost:
Handling HTTP requests may take longer while any deferred initialization occurs.
Failures that would normally occur at startup will now not occur until later.
Please see the related blog post for a broader discussion of the new feature and guidance on when it should and should not be enabled.
</code>Java Architecture Diary
Committed to sharing original, high‑quality technical articles; no fluff or promotional content.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.