Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Spring Boot: A Work of Art

DZone 's Guide to

Spring Boot: A Work of Art

Here's how you can get started on your first Spring Boot project!

· Java Zone ·
Free Resource

Spring Boot is a work of art. And yes, you should definitely believe the hype. It really is that good. Using Spring Boot, teams with significantly less experience with the Java and Spring frameworks can start delivering value with just a little training.

Spring Boot takes away most of the challenges associated with normal Spring app development. However, having said that, Spring Boot is an inherent part of the overall Spring framework.

Its primary objective is to bring rapid application development to the world of Spring.

And how does it achieve that?

The concept is pretty simple. Spring Boot provides an opinionated framework to do stuff by means of starter templates. These templates make it exceedingly easy to bootstrap the application.

The best part, however, is that all of it works flawlessly.

So, let's get started with Spring Boot.

Creating a Spring Boot Application

The best way to create a new Spring Boot application is to use https://start.spring.io. This is what is more commonly known as the Spring Initializr. It's also my favorite place on the Internet. It helps you cook up a working Spring Boot application in almost no time.

On the page that opens, you need to fill in a few details. In the field Group, you can enter the high-level package name. This could be your domain. The artifact could be the name of your application.

You can click on Switch to Full Version to see all the details you can enter

I have entered the Group as com.progressivecoder.demo and Artifact as spring-boot-starter. See the image below:

Note that we have selected the Maven Project at the top. You could also use Gradle. In the languages dropdown, you could opt for Kotlin or Groovy. In this example, we have selected Java.

You can also play around with the Spring Boot version. At the time of writing this, the latest stable version was 2.1.1, which is what I have selected.

The rest of the details are pretty self-explanatory. And I would not recommend changing anything if you are just starting out with Spring Boot.

The next important step is to select the various packages or features I want in the application. This step is similar to selecting the dependencies in a typical Maven or Gradle project. In the dialog box, you can scroll down to see the entire list of curated dependencies available.

For the purpose of this post, we would select a few important dependencies like Web, Rest Repositories, JPA, H2, and Actuator. We would get into the details of these dependencies later.

At this point, we can now click on the big green button that says Generate Project. Alternatively, you can press Alt + Enter. The project will be downloaded to your computer.

Running the Application

Running the application is pretty simple. Unzip the downloaded project to a suitable place in your computer's file system. Then, open it in your favorite IDE.

My favorite IDE for Java is IntelliJ from JetBrains. And I wouldn't hesitate in recommending the same to you. A community edition is available at this location.

Once you open the project, it might take a moment to pull all the dependencies and build the overall project structure. You can grab a coffee during this time.

Once everything is set up, you could simply run the project using IntelliJ's Maven plugin.

The simplest command to run it is clean package spring-boot:run:


Apply and click OK, and then, run the application using the play button that appears near the top-right area of the editor.

Once the build completes successfully, you will be able to see the application startup on port 8080 (unless you aren't using that port for something else).

You can now check whether your application is actually running successfully by visiting http://localhost:8080/actuator/health. If everything is fine, you would see a message saying {"status":"UP"} displayed in the browser window.

With this, we have successfully set up a new Spring Boot application. Now, we can work on this application and add some real functionality. But before that, we need to understand what happens under the hood when you use Spring Boot.

In the next post, we will try and understand how a typical Spring Boot application works. Stay tuned!

Topics:
spring boot application ,spring boot ,spring for beginners ,spring boot for beginners ,java ,tutorial ,run ,maven

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}