Over a million developers have joined DZone.

Yet Another Spring Boot Application (Part 1)

Spring Boot is much more popular, a trend that fits with increased use of microservices. Learn more about using Spring Boot with this in-depth look at creating a Spring Boot app.

· Integration Zone

Learn how API management supports better integration in Achieving Enterprise Agility with Microservices and API Management, brought to you in partnership with 3scale

Spring Boot applications seem to be gaining traction with the increased popularity of microservices. In this post, we will be covering a basic skeleton project for a Spring Boot application that simply runs with a number of default endpoints.

For starters, I opted for Spring’s introduction to Spring Boot as it is as concise as they get:

Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can “just run.” [Source]

This is possible due to the out-of-the-box support for several features from a number of modules. The latter include the ability to easily add embedded servlet containers like Tomcat and Jetty, opinionated starter POMs, possibility of configuration by Java (instead of the XML) and a number of analytics such as health checks and metrics. For more information, check out the project website.

What Will We Be Doing?

In this and upcoming posts, we will create a Spring Boot application, initially an “empty” application that simply starts with some readily-available endpoints and gradually developing a fully fledged application with its own REST-based API. However, in this particular post, we will explain the base skeleton project required, which source code can be found here. Briefly, we will cover:

  • the necessary dependencies
  • specifying the runnable class
  • running the server
  • checking that the server works correctly
  • teaching a group of monkeys to play The Who’s Baba O’riley

Well, maybe not the last one, but we will be covering the rest! Note that a basic understanding of Maven is assumed (if not, go to their tutorial, it is pretty straight forward for what we need here!).

Let’s Start!

After cloning the repository for the skeleton project, we are presented with the following project structure:

+- tutorials-springboot
   +- src
      +- main
         +- java
           +- com
              +- tutorials
                 +- springboot
                    -- Application.java
   -- pom.xml

Starting with the project’s POM file, Spring Boot offers a parent project (spring-boot-starter-parent) for application to kick start development. In order to mitigate this reduced flexibility in project structure (as we might want to extend our own project parent eventually), we decide to make use of Spring Boot’s Bill of Materials or BOM for short:



The usage of a BOM allows the correct version dependencies in a number of opinionated POMs to be used. Further insight on Maven’s BOM concept can be found in this article.

Now, for the Spring Boot application to run we employ three main modules:

  • actuator — provides a number of production-ready features, such as health verification, metrics and graceful shutdown. More extensive information can be found here.
  • web — includes a number of modules for the creation of a web application, Spring MVC and amongst others, handling and mapping of HTTP requests.
  • tomcat —enables the usage of an embedded tomcat instance with no requirement for deployment of WAR files.

Finally, we set the build to use the spring boot maven plugin, which simplifies application execution by:

  • grouping all the jars on the classpath into one jar;
  • flags the runnable class by searching for the main method (public static void main), and
  • provides a built-in dependency resolver. [Source]

Specifying the Runnable Class

package com.tutorials.springboot;


public class Application {

    public static void main(final String[] args) {
        SpringApplication.run(Application.class, args);


We annotate our Application class with the convenient annotation @SpringBootApplication, which is essentially a collection of annotations that:

  • flag the class as a source for bean definitions (@Configuration);
  • enables the addition and configuration of beans specified in the classpath and other locations to be loaded, and other property settings (@EnableAutoConfiguration);
  • and adds scanning for the current package (in our casecom.tutorials.springboot) for other components, configurations and services (@ComponentScan). [Source]

Albeit empty (as we defined no custom endpoints apart from the ones provided by the actuator), we now have our Spring Boot application! We can launch the web application by running:

mvn spring-boot:run

Once the server has started, open the browser and go to localhost:8080, and depending on the browser, we are “welcomed” with some form of 404 message. This is perfectly understandable, since we have not defined any business endpoints, and hence, this is handled by a default JSON response as specified by the actuator /error endpoint.

Amongst the endpoints supplied by the actuator, we can send a request to the health endpoint, /health, where we are greeted with minor analytics message in JSON format:


And We’re Done…From the First Part!

Well, that pretty much concludes our initial overview of Spring Boot and the first part of our application! There will be additional parts to this, and hopefully in the next part, I should be covering a basic endpoint implementation and a proper web integration test for it.

If you have any questions or requests, feel free to leave them in the comment section below!

Unleash the power of your APIs with future-proof API management - Create your account and start your free trial today, brought to you in partnership with 3scale.

java,spring boot,tutorial

Published at DZone with permission of Joseph Masini. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}