Getting Started with Spring Boot

Deshani Warnakulasuriya
4 min readMay 3, 2021

After learning Java next best thing to learn is java Spring Boot.Combination of Java and Java Spring Boot helps to create java applications pretty easily.

To get started with Spring Boot will use Spring Boot initializr. Spring Boot initializr gives the starter package that help to create first spring application. Click here to navigate to spring initializr.

In the spring initializr choose Maven as the java package manager. After that choose Java as the language. Next for the spring boot version, keep the default version. Then we need to set up meta data for the application(for this you can give the details as you prefer). Then choose the package as the jar and for the Java version select the version that you have in your computer. After everything is set up it should look like the below image.

After finishing the above steps you can now click the button add dependencies. Since this is a small project we will only include spring web for this project. Then click on the generate button to generate the sample project. The reason to use spring initializr because it help to get some boiler plate code out of the way, so we can focus on the application code.

After the zip file is downloaded move it to any place you like in your computer and extract the zip file. Then to add the sample code I am going to use Intelij as my IDE you can use any IDE as your preference. Next import the demo project to the Intelij IDE and package manager should be selected as Maven in the selection list in the import project from external model. Then click finish and the project will loaded up.

So to check everything is working fine let’s run the program. To run the program go to the Demo application and right click on it, then click on the run Demo application. Check the below image.

So the spring application running on port 8080. Lets stop the application for now and add some code to create a simple web application.

I will create a web application that can print a message at local host 8080. To do this we need a Rest controller. It is going to be at it own class and will call it as WelcomeController. To this controller will give the annotation of “@RestController”. @RestController is a component that contain routes of the application and what will happen when the users visit those routes.

Next to setup a route we will add a method call getWelcome() and then we will return message that we need to display in the localhost:8080 page. To make this function a route we need to add “@RequestMapping” annotation and we need to give the path to the annotation. Since we are doing a get request we don’t need to add because default method is get request. If you want to do POST or any other request then you have to mention the method in the @RequestMapping annotation.These annotations are build in spring application.

Check the below image for better understanding of what I said above.

So with the use of Request Controller and with Request Mapping Controller annotation, when we run the app and go to the localhost homepage(http://localhost:8080/) we will see our greeting.

With this application we have running REST API with one get endpoint at home page.

This is a example of simple web application to getting started with springboot. If you want create quick REST API microservice using JAVA, SpringBoot is a very good choice.

Hope you learn something new.

I will meet you again with a new blog post, until then stay safe.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Deshani Warnakulasuriya
Deshani Warnakulasuriya

Written by Deshani Warnakulasuriya

I am a Software Engineer who loves to learn and loves to share what I know.

No responses yet

Write a response