10 Hidden Spring Boot 3 Settings to Supercharge Your Application Performance
This article reveals ten hidden Spring Boot 3 configuration tricks—from disabling the whitelabel error page and shrinking Tomcat threads to enabling HTTP/2, tuning HikariCP, caching static assets, and leveraging Actuator metrics—each illustrated with code snippets and practical steps to boost application performance.
1. Introduction
Spring Boot is famous for "convention over configuration", but many low‑level properties can make your application faster, lighter, and more production‑ready.
2. Practical Cases
2.1 Disable the default Whitelabel error page
server:
error:
whitelabel:
enabled: falseEliminates unnecessary rendering overhead and allows you to implement a custom error handling mechanism.
2.2 Reduce Tomcat thread‑pool size
server:
tomcat:
threads:
max: 50
min-spare: 10For small services the default 200 threads waste memory; lowering the pool improves throughput.
2.3 Enable HTTP/2 support
server:
http2:
enabled: trueHTTP/2 provides multiplexed connections, delivering noticeable performance gains for micro‑services and APIs. It usually requires TLS.
Generate a keystore:
keytool -genkeypair -alias pack-http2 -keyalg RSA -keysize 2048 -storetype PKCS12 -keystore keystore.p12 -validity 3650Add SSL configuration:
server:
ssl:
enabled: true
key-store: classpath:keystore.p12
key-store-password: 123123
key-store-type: PKCS12
key-alias: pack-http2Verify with a simple controller and Postman:
@RestController
public class Http2Controller {
@GetMapping("/http2/msg")
public String getChatbotResponse(@RequestParam String message) {
return message;
}
}2.4 HikariCP connection‑pool tuning
spring:
type: com.zaxxer.hikari.HikariDataSource
hikari:
minimumIdle: 50
maximumPoolSize: 50
autoCommit: true
idleTimeout: 30000
maxLifetime: 1800000
connectionTimeout: 30000Reduces the overhead of repeatedly creating and destroying database connections, improving stability under high load.
2.5 Cache static resources
spring:
web:
resources:
cache:
period: 3600s
chain:
cache: trueStatic assets (JS, CSS, images) stay cached, cutting the number of server requests.
2.6 Disable JPA Open‑In‑View
spring:
jpa:
openInView: falseFor APIs, keeping the DB session open after the view is rendered hurts performance. If you need to avoid LazyInitializationException, you can explicitly load associations with JOIN FETCH or @EntityGraph, or use projection interfaces.
@EntityGraph(attributePaths = {"orders"})
User findByIdWithOrders(Long id);2.7 Enable response compression
server:
compression:
enabled: true
mime-types:
- application/json
- application/xml
- text/html
- text/plain
min-response-size: 1024Significantly reduces bandwidth consumption for JSON responses.
2.8 Tune JVM G1GC parameters
JAVA_OPTS="-XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:+ParallelRefProcEnabled"Provides low‑latency garbage collection suitable for high‑throughput applications.
2.9 Enable lazy initialization
spring:
main:
lazy-initialization: trueDefers bean creation until first use, dramatically speeding up startup time.
2.10 Use Actuator metrics for auto‑tuning
management:
endpoints:
web:
exposure:
include:
- health
- metrics
- prometheus
endpoint:
health:
show-details: alwaysMonitor memory usage, connection‑pool stats, and HTTP throughput, then adjust configurations based on real‑time data.
Conclusion
Applying these ten hidden configuration options can noticeably improve Spring Boot 3 performance, reduce resource consumption, and make the application more suitable for production environments.
Spring Full-Stack Practical Cases
Full-stack Java development with Vue 2/3 front-end suite; hands-on examples and source code analysis for Spring, Spring Boot 2/3, and Spring Cloud.
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.
