Open In App
Related Articles

How to Create a Simple Spring Application?

Like Article
Save Article
Report issue

Java language is one of the most popular languages among all programming languages. There are several advantages of using the java programming language, whether for security purposes or building large distribution projects. One of the advantages of using JAVA is that Java tries to connect every concept in the language to the real world with the help of the concepts of classes, inheritance, polymorphism, etc. There are several other concepts present in java that increase the user-friendly interaction between the java code and the programmer such as generic, access specifiers, annotations in java, etc these features add an extra property to the class as well method of the java program. In this article, we will discuss how to create a simple spring application. To create a simple spring application we need a dependency spring web that helps to create a spring server. First, we need to establish the spring application in our project.

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 that are supported by JVM. Here, we will create the structure of an application using a spring initializer and then use an IDE to create a sample GET route. Therefore, to do this, the following steps are followed:

Step 1: Go to this link. Fill in the details as per the requirements. For this application:

Project: Maven
Language: Java
Spring Boot: 2.5.6
Packaging: JAR
Java: 11
Dependencies: Spring Web

Click on Generate which will download the starter project.

Step 2: 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 as pictorially depicted below as follows:

Note: In the Import Project for Maven window, make sure you choose the same version of JDK which you selected while creating the project.

Step 3: Go to src > main > java >, create a java class with the name Controller and add the annotation @RestController. Now create a GET API as shown below:

Example 1:


// Class
public class Controller {

   public void insert(@PathVariable("name") String name, @PathVariable("age") int age) {
       // Print and display name and age

This application is now ready to run.

Step 4: Run the SpringBootAppApplication class and wait for the Tomcat server to start.

Note: The default port of the Tomcat server is 8080 and can be changed in the file.

Step 5: Lastly now go to the browser and enter the URL localhost:8080. Observe the output and now do the same for localhost:8080/hello/Aayush/2



Last Updated : 19 Nov, 2021
Like Article
Save Article
Share your thoughts in the comments
Similar Reads