Home » Spring Boot » SpringBoot Restful WebService

SpringBoot Restful WebService

In this post,I am going to explain the simplest way to create a restful web-service using spring boot.

Step 1: Use the below pom.xml.Here we are downloading all parent dependencies of spring boot starter using “spring-boot-starter-parent”.Also we are downloading jars related to spring boot web using “spring-boot-starter-web” for creating restful webservices. Both of these are mandatory to create a restful spring boot application.

Step2 : Create a class SpringBootRestApp.java and use @SpringBootApplication to make the appication as spring boot application.Use @ComponentScan to scan the package where configurations are defined.

Step 3:Create a controller class Ai1Controller.java and use @RestController annotation to make this as a rest controller class.So any rest call from client will hit this class.We have two methods welcome() and getHelloWorld() with request mapping as “/” and “/hello”.So any rest call from client with this request mapping will hit corresponding method and will get response accordingly.

Step 4 :Your project should look like below.

After this run the application by selecting SpringBootRestApp and click on run.
You will get output like below.Tomcat will by default starts on 8080 port.

Step 5 :
Click on the below url to get our put
1. http://localhost:8080/
Output Response:

2. http://localhost:8080/hello
Output Response:

Leave a comment

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

12 + fourteen =