With the help of Maven, Spring Boot provides means to run a web application on several embedded servers.

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.