Spring Boot is powerful yet flexible. It tries to auto-configure most of the stuff for you so that you can get up and running quickly with your application.

It uses sensible defaults during auto-configuration but also gives you the flexibility to change those defaults by just tweaking a few things.

In this article, you’ll learn about the most common configuration tweaks that might need to do in your application.

Changing the embedded server in Spring Boot

Spring Boot uses Tomcat as the default embedded server. If you wanna use some other popular server like Jetty or Undertow then you just need to exclude tomcat dependency and add the other server dependency.

1. Using Jetty as the embedded server in Spring Boot

<!-- Exclude tomcat dependency -->
<!-- Include jetty dependency -->

2. Using undertow as the embedded server in Spring Boot

<!-- Exclude tomcat dependency -->
<!-- Include undertow dependency -->

Changing the default server port and context path in Spring Boot

By default, Spring Boot runs your application on port 8080 with the context path /.

If you wanna change the default port and context path, then it’s just a matter of specifying the corresponding values in the application.properties file -

# HTTP Server port

# Make the application accessible on the given context path (http://localhost:8080/myapp)

Enabling GZip compression in Spring Boot

GZip compression is a very simple and effective way to save bandwidth and improve the speed of your website.

It reduces the response time of your website by compressing the resources and then sending it over to the clients. It saves bandwidth by at least 50%.

GZip compression is disabled by default in Spring Boot. To enable it, add the following properties to your application.properties file -

# Enable response compression

# The comma-separated list of mime types that should be compressed

# Compress the response only if the response size is at least 1KB

Note that, GZip compression has a small overhead. Therefore I’ve added a min-response-size property to tell spring boot server to compress the response only if the size is more than the given value.

Enabling HTTP/2 support in Spring Boot

HTTP/2 is an improvement over the HTTP1 protocol. It improves the page load speed of your website by employing several mechanisms like data compression, server push, multiplexing of multiple requests over a single TCP connection etc.

You can enable HTTP2 in spring boot with the following property, if the server has support for it -

# Enable HTTP/2 support, if the current environment supports it

Enabling browser caching of static resources in Spring Boot

Browser caching is another way to improve the page load speed of your website. You can set cache-control headers to tell browsers to cache static resources until a certain period of time.

Browser caching is disabled by default in Spring Boot. You can enable caching by setting the following properties in the application.properties file.

# Maximum time the response should be cached (in seconds) 

# The cache must re-validate stale resources with the server. Any expired resources must not be used without re-validating.

Following are few other cache related properties that you should be aware of -

# The resources are private and intended for a single user. They must not be stored by a shared cache (e.g CDN).
spring.resources.cache.cachecontrol.cache-private= # set a boolean value true/false

# The resources are public and any cache may store the response.
spring.resources.cache.cachecontrol.cache-public= # set a boolean value true/false

Configuring multipart file uploads in Spring Boot

Multipart file uploads are enabled by default in Spring Boot with the following property -


But there are few other default multipart properties that you might need to change.

By default, Spring Boot allows you to upload a file with a maximum size of 1MB. You might need to change this to the desired value as per your requirements.

Following is the complete set of properties -

# Write files to disk if the file size is more than 2KB.

# The intermediate disk location where the uploaded files are written

# Maximum file size that can be uploaded

# Maximum allowed multipart request size


In this short article, you learned how to tweak Spring Boot’s default configurations as per your needs. You can find a full index of common application properties on the following official Spring Boot page -

Spring Boot Common application properties

Whenever you need to configure anything in your spring boot application, the first thing you should do is - check the above common application properties page. Most probably, you’ll find a property for configuring the stuff that you’re looking for.

More resources

You might also wanna check out the following articles on Spring Boot configuration -

I hope you enjoyed this article. As always, Thanks for reading.