DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > Spring Boot: Changing/Configuring the Default Embedded Server

Spring Boot: Changing/Configuring the Default Embedded Server

In this post we take a look at how to set and configure the default embedded web server used in your Spring Boot application.

Gaurav Rai Mazra user avatar by
Gaurav Rai Mazra
·
Feb. 17, 17 · Java Zone · Tutorial
Like (15)
Save
Tweet
148.02K Views

Join the DZone community and get the full member experience.

Join For Free

In a previous post, we created a web-based Spring Boot application that uses Embedded Tomcat as the default server running on the default port, 8080. Spring Boot supports Tomcat, Undertow, and Jetty as embedded servers. Now, we will change and/or configure the default embedded server and common properties to all the available servers.

Spring Boot provides a convenient way of configuring dependencies with its starters. For changing the embedded server, we will user its spring-boot-starter-undertow.

Adding Dependencies

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-undertow</artifactId>
</dependency>


spring-boot-starter-web comes with Embedded Tomcat. We need to exclude this dependency.

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
  <exclusions>
    <exclusion>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
    </exclusion>
  </exclusions>
</dependency>


This is all we need to do to change the embedded server. There are some generic properties that are applicable for every server, and some server-specific properties that we can tweak to improve performance. Let's change some of the server properties.

Changing the Default Server Port

The server.port property is used for configuring the port on which our Spring Boot application should run.

Enabling Compression on Responses

You can enable compression on responses sent by the server and can tweak the mimeTypes, and minResponseSize for compression. By default, compression is disabled. The default property value for mimeTypes is: text/html, text/xml, text/plain, text/css, text/javascript,

application/javascript. The default value for minResponseSize is 2048 bytes.

Other Server Properties

You can also enable SSL, modify maxHttpPostSize, contextParameters, contextPath , and other server-related properties. To know more, see the org.springframework.boot.autoconfigure.web.ServerProperties class.

Configuring Server-Specific Properties

You can also change embedded server-specific properties. In our example, we changed the embedded server to Undertow and tweaked its ioThreads and workerThreads properties.

A sample properties file, which have the above property changes, would look like so:

server:
  port: 8082
  undertow: 
    ioThreads: 15
    workerThreads: 150
    accesslog: 
      enabled: true
  compression: 
    enabled: true
    mimeTypes: text/xml, text/css, text/html, application/json
    minResponseSize: 4096

spring:
  application: 
    name: gaurav-bytes-embedded-server-example


I hope this article is informative and helpful. You can grab the full example code on Github.

Spring Framework Spring Boot Property (programming)

Published at DZone with permission of Gaurav Rai Mazra, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Streaming ETL with Apache Kafka in the Healthcare Industry
  • Getting Started With RSocket Kotlin
  • The Developer's Guide to SaaS Compliance
  • Modern Application Security Requires Defense in Depth

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo