RESTful web services using spring boot

The following two tabs change content below.
Prasad Kharkar is a java enthusiast and always keen to explore and learn java technologies. He is SCJP,OCPWCD, OCEJPAD and aspires to be java architect.

Latest posts by Prasad Kharkar (see all)

We will see how to create RESTful web service using spring boot in this article. I had to include this in the middle of angular articles because we are looking for a bigger picture. We are going to create an end to end enterprise app using client side as well as server side technologies.

 

RESTful web services using spring boot:

Without going into too much details, let us start building it as quickly as possible. Below tools are being used.

Create a gradle project in Eclipse:

Project Structure

Project Structure

Navigate to File > New > Other > Gradle > Gradle Project

 

and name it SpringBoot.

You will have a project created with its structure as depicted in this screenshot.

  • build.gradle is our build file.
  • src/main.java : Here we will store java files

 

buid.gradle:

HelloWorld.java:

This is our model class which simply holds the message.

HelloWorldController:

  • @RestController¬†specifies that this class will be treated as a spring controller.
  • @RequestMapping(“/sayHello”) :¬†This means method is mapped to path http://localhost:8080/sayHello.

We are done creating RESTful web services using spring boot. Let us create an actual class that starts the application and boots the services.

Application.java:

All magic happens here, run this class as normal java application and spring will do all the process and start its embedded tomcat server. Once tomcat is started, simply navigate to your browser and hit http://localhost:8080/sayHello

as soon as hit the url, it should be able to display hello world message as below.

I hope this small article helped create RESTful web services using spring boot.

 

Share Button

4 comments for “RESTful web services using spring boot

  1. Ken
    September 6, 2017 at 1:16 pm

    Hi is it possible to get this to working with just VS code?

  2. Pranaya
    October 5, 2017 at 12:19 pm

    {Good example with Gradle.

Leave a Reply

Your email address will not be published. Required fields are marked *