In this post, we’ll take you through the steps of building a basic Spring Boot application using a practical example. Specifically, we’ll leverage the Spring Tool Suite to set up the Spring Boot application. Follow our illustrated, step-by-step instructions to gain a comprehensive understanding of writing a Hello World program with Spring Boot.

Open Spring Tool Suite

You can obtain the Spring Tool Suite by visiting the official Spring website and downloading it from the provided link. Once the download is complete, proceed to install STS by following the step-by-step instructions outlined on the Spring website. After the installation process, locate the Spring Tool Suite icon and click on it to initiate the application. Upon launching, the welcome screen will greet you with a presentation that resembles the following visual.

The Spring Tool Suite is a robust application that may require some time to load and open due to its extensive features. The efficiency of this STS application largely depends on the available RAM on your computer or laptop. If your device has ample RAM, the loading and opening processes should be relatively swift. Conversely, a lower RAM capacity may result in longer loading times. Upon launching the Spring Tool Suite application, the interface will be presented in a manner similar to the following snapshot.

Create Spring Boot Project

Once you have initiated the Spring Tool Suite application, you can proceed to craft a basic Spring Boot project to develop a Hello World program. To create a Spring Boot project, navigate to the “File” menu and select “New” followed by “Spring Starter Project.” The image below provides a visual representation of the File menu for your reference.

Upon selecting “Spring Starter Project,” a new window will unfold, prompting you to input the particulars for your new Spring Starter Project. In the “Name” text box, specify a distinctive project name. By default, the project will be established within the STS workspace. If you prefer an alternative location, simply uncheck the “Use default Location” option and proceed to select your desired project location. This flexibility allows you to tailor the project setup according to your preferences.

Complete the requisite details in the provided fields, including Group, Artifact, Description, and Package. The Group and Artifact entries play a crucial role in generating Maven JARs.

  1. Group: This signifies the group or organization to which your project belongs. It is a way of categorizing projects in the Maven repository.
  2. Artifact: This represents the unique identifier for your project. It is used to name the JAR file when it’s built.
  3. Description: Offer a brief yet informative description of your project to provide clarity on its purpose and functionality.
  4. Package: Define the package name, which serves as the initial Java package for creating all Java files. It organizes and categorizes your code files within the project structure.

Ensure accuracy and coherence in these details as they contribute to the organization and identification of your Spring Boot project.

Verify that the language for your Spring Starter Project is set to Java and that the appropriate Java version is configured.

Once you’ve input all the necessary information, proceed by clicking the “Next” button located at the bottom. The subsequent page will display a comprehensive list of dependencies accessible within the Spring Tool Suite. If specific dependencies are required for your project, you can select and add them at this stage. However, for a basic Hello World program, no additional dependencies are needed.

To advance to the next window, simply click the “Next” button. This will allow you to proceed with the project creation process without adding any extra dependencies, streamlining the setup for your Hello World program.

Once you reach the site info window, which is displayed below, take the final step to create your Spring Boot application by clicking the “Finish” button. This action initiates the process of generating your Spring Boot project based on the provided details and configurations.

Once initiated, the Spring Tool Suite will automatically generate a Spring Boot application, loading all the necessary Spring Boot dependencies specified within the project. Upon the completion of the loading process, the Spring Boot application will be presented in the Spring Tool Suite interface, resembling the depiction shown below.

Run Spring Boot Application

The main class for your Spring Boot application will be automatically generated in the specified package during the creation of the Spring Boot project. This package can be found within the src/main/java folder of your project directory. To view and access the Spring Boot application’s main Java class, simply expand the corresponding package in your project structure, following the visual representation illustrated in the provided image. This main class serves as the entry point for your Spring Boot application

To execute your Spring Boot application, navigate to the Run Menu in the Spring Tool Suite and choose the “Run” option. Alternatively, you can press “Ctrl + F11” for a quick shortcut. The Run Menu will be similar to the illustrated image below.

Upon selecting the “Run” option, a “Run As” dialogue box will emerge, providing you with choices on how to execute the Spring Boot application. Opt for “Spring Boot App” from the available list and confirm by clicking the “Ok” button. It’s important to note that this selection is typically presented only once. Subsequent launches of the Spring Boot application will automatically utilize the “Spring Boot App” option, streamlining the process for future executions. Your Spring Boot application is now set to run seamlessly using this configuration.

Following the click on the “Ok” button, the Spring Boot project will be executed, and the progress and details of the execution will be visible in the console window. The console will display an execution log, capturing various stages and information about the running Spring Boot application. Additionally, Log4j, a logging utility, will be automatically configured, and the logs will be presented using Log4j.

Customize the Spring Boot Project

As shown in the image below, open the spring boot main java class and add a system out println line with a sample string.

After incorporating the System.out.println statement into the main Java class, restart your Spring Boot project. Upon restarting, the console window will display the output of the added line during the execution of the Spring Boot application. The console output will reflect the message specified in the System.out.println statement, providing a visual confirmation of the successful integration of your code modification. The appearance of the console window during this process is similar to the representation in the accompanying image.

Leave a Reply