How to deploy and run a Spring Boot application on Jetty

Dariusz Wawer

Senior IT Consultant

  • October 5, 2015

Contents

It is still spring, so deploying to an existing environment is also possible.  Unfortunately, running a Spring Boot application on Jetty server requires some tweaks in its pom.xml. If you don’t feel like reading further and want to jump right into action, here’s an example application with simple setup (spring boot, hsql database, hibernate), ready to use as a base for your project.

Jetty instead of Tomcat for spring-boot:run

The default embedded web server used by spring-boot is Tomcat. It is, however, fairly easy to switch to Jetty:

We exclude the starter-tomcat dependency and add starter-jetty.

Deploying on Jetty Application Server

After following the steps from previously linked Spring blog post and deploying our webapp on jetty, this exception got thrown when starting the application:

Apparently, even though starter-tomcat was excluded, spring attempted to load Tomcat’s DataSource implementation.

Using a custom ConnectionPool can remedy the problem. There are several CP impementations available, like DBCPHikari, C3p0, BoneCP…  We chose Hikari. The dependency added to pom.xml:

For it to work the tomcat-jdbc dependency had to be excluded from starter-jdbc:

Migrating from tomcat-jdbc to Hikari

Hikari requires differently named properties to configure a DataSource. Namely, instead of url, a jdbcUrl is required. A config could look like this:

Details about configuring HikariCP can be found in Hikari’s documentation. If you chose any other connection pool implementation, remember to check their documentation for details about configuring them.

An example application

Here’s an example application which should run flawlessly on jetty and through spring-boot:run. It’s a simple REST service with two methods: /set/{param}/{value} and get/{param} which uses an embedded HSQL database and Hibernate as ORM.

Looking for a software development company?

Work with a team that already helped dozens of market leaders. Book a discovery call to see:

  • How our products work
  • How you can save time & costs
  • How we’re different from another solutions

footer-contact-steps

We keep your data safe: ISO certified

We operate in accordance with the ISO 27001 standard, ensuring the highest level of security for your data.
certified dekra 27001
© 2025 Pretius. All right reserved.