How to Run Spring Boot ApplicationIn this section, we will create and run a simple Spring Boot application. Creating a Spring Boot ApplicationStep 1: Open the Spring Initializr https://start.spring.io/. Step 2: Select the Spring Boot version 2.2.2.BUILD-SNAPSHOT. Step 3: Provide the Group name. We have provided the Group name com.javatpoint. Step 4: Provide the Artifact. We have provided the Artifact spring-boot-application-run. Step 5: Add the Spring Web dependency. Step 6: Click on the Generate button. When we click on the Generate button, it wraps all the specifications related to application into a Jar file and downloads it to the local system. Step 7: Extract the jar file. Step 8: Copy the folder and paste it in the STS workspace. Step 9: Import the project. File -> Import -> Existing Maven Projects -> Next -> Browse -> Select the folder spring- spring-boot-application-run -> Select Folder -> Finish It takes time to import the project. When the project imports successfully, we can see it in the Package Explorer section of the IDE. We see that two files are automatically created, one is pom.xml, and the other is Application.java file. The pom.xml file contains the all the dependencies, application name, Spring Boot version, group name, artifact, and other plugins. pom.xml The main class is a class that contains the main() method. It starts the Spring ApplicationContext. It is the class that we run for the execution of the application. SpringBootApplicationRun.java Step 10: Create a Controller. We have created a controller with the name HelloWorldController. HelloWorldController.java Now we have created all the required files related to Spring Boot application. Run the Spring Boot applicationFor running the Spring Boot application, open the main application file, and run it as Java Application. When the application runs successfully, it shows the message in the console, as shown below. Now, open the browser and invoke the URL http://localhost:8080. It shows the message that we have returned to the controller. Next TopicSpring Boot Change Port |