Skip to content
Related Articles

Related Articles

How to create a basic application in Java Spring Boot

Improve Article
Save Article
  • Last Updated : 28 Jan, 2022
Improve Article
Save Article

Spring MVC is a widely used module of spring which is used to create scalable web applications. But the main disadvantage of spring projects is that configuration is really time-consuming and can be a bit overwhelming for the new developers. Making the application production-ready takes some time if you are new to the spring. The solution to this is Spring Boot. Spring Boot is built on the top of the spring and contains all the features of spring. In this article, we will see how to create a basic spring boot application.
Spring Initializr is a web-based tool using which we can easily generate the structure of the Spring Boot project. It also provides various different features for the projects expressed in a metadata model. This model allows us to configure the list of dependencies which are supported by JVM. Here, we will create the structure of an application using spring initializr and then use an IDE to create a sample GET route. Therefore, to do this, the following steps are followed: 

  1. Go to Spring Initializr
  2. Fill in the details as per the requirements. For this application: 

Project: Maven 
Language: Java 
Spring Boot: 2.2.8 
Packaging: JAR 
Java: 8 
Dependencies: Spring Web 

  1. Click on Generate which will download the starter project. 

  1. Extract the zip file. Now open a suitable IDE and then go to File->New->Project from existing sources->Spring-boot-app and select pom.xml. Click on import changes on prompt and wait for the project to sync. 

  1. Note: In the Import Project for Maven window, make sure you choose the same version of JDK which you selected while creating the project.
  2. Go to src->main->java->, create a java class with name 
    as Controller and add the annotation @RestController. Now create a GET API as shown below:


public class Controller {
    // One syntax to implement a
    // GET method
    public String home()
        String str
            = "<html><body><font color=\"green\">"
              + "<h1>WELCOME To GeeksForGeeks</h1>"
              + "</font></body></html>";
        return str;
    // Another syntax to implement a
    // GET method
        method = { RequestMethod.GET },
        value = { "/gfg" })
    public String info()
        String str2
            = "<html><body><font color=\"green\">"
              + "<h2>GeeksForGeeks is a Computer"
              + " Science portal for Geeks. "
              + "This portal has been "
              + "created to provide well written, "
              + "well thought and well explained "
              + "solutions for selected questions."
              + "</h2></font></body></html>";
        return str2;

  1. This application is now ready to run. Run the SpringBootAppApplication class and wait for the Tomcat server to start. 

  1. Note: The default port of the Tomcat server is 8080 and can be changed in the file.
  2. Now go to the browser and enter the URL localhost:8080. Observe the output and now do the same for localhost:8080/gfg

On running the above application, the following output is generated: 

Conclusion: By following the above steps, we have created a simple RESTful route with some message in it. In order to make a more complex application, more RESTful routes are added to perform the CRUD operations on the server.

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!