surevine bg

Spring as a Java container abstraction – switching to Undertow

Return to Resource Centre

13 September 2018

Guest Blogger

Spring MVC abstracts the Java servlet container implementation away from you almost completely, this allows you to migrate from Tomcat quite easily.

This post is part of the “Spring Boot Primer” series.

Unless you have somehow tied yourself into Tomcat, perhaps by customising its configuration, or directly taking advantage of some Tomcat-specific feature, then all that is required is taking the default spring-boot-starter-web dependency:

pom.xml
1
2
3
4
5
6
7
8
<dependencies>
  ...
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
  ...
</dependencies>

and then replacing it with the following:

pom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<dependencies>
  ...
  <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>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-undertow</artifactId>
  </dependency>
  ...
</dependencies>

All this does is exclude Tomcat from the web starter, and lets you add either Undertow or Jetty as an alternative Java web container.

Enjoying this blog series? Take a look at our other technical blog posts

Company

Surevine Limited

Registered in England and Wales with number 06726289

Registered Office

125 Wood Street, LONDON EC2V 7AW, United Kingdom

Find Us

Get in touch, we’d love to hear from you.

Useful Links

Surevine Logo
surevine security innovation of the year
Cyber Essentials Certified
Joscar Registered
LRQA Certified

© 2024 Surevine All rights reserved

LegalPrivacyCookie policyAccessibilityResponsible disclosure policy