How to Run Your First Spring Boot Application in Eclipse IDE?
Spring Boot is built on the top of the spring and contains all the features of spring. And is becoming a favorite of developers these days because of its rapid production-ready environment which enables the developers to directly focus on the logic instead of struggling with the configuration and setup. Spring Boot is a microservice-based framework and making a production-ready application in it takes very little time. Following are some of the features of Spring Boot:
- It allows avoiding heavy configuration of XML which is present in spring
- It provides easy maintenance and creation of REST endpoints
- It includes embedded Tomcat-server
- Deployment is very easy, war and jar files can be easily deployed in the tomcat server
For more information please refer to this article: Introduction to Spring Boot. So in the article Create and Setup Spring Boot Project in Eclipse IDE we have explained how to create a simple spring boot project. In this article, we are going to create a simple “Hello World” application and run it inside our Eclipse IDE.
- Create and set up Spring Boot Project in IDE.
- Add the spring-web dependency in your pom.xml file.
- Create one package and name the package as “controller in the project.
- Run the Spring Boot application.
Step 1: Create and Setup Spring Boot Project in Eclipse IDE
You may refer to this article Create and Setup Spring Boot Project in Eclipse IDE and create your first Spring Boot Application in Eclipse IDE.
Step 2: Add the spring-web dependency in your pom.xml file. Go to the pom.xml file inside your project and add the following spring-web dependency.
Step 3: In your project create one package and name the package as “controller”. In the controller, the package creates a class and name it as DemoController.
We have used the below annotations in our controller layer. Here in this example, the URI path is /hello.
- @Controller: This is used to specify the controller.
- @RequestMapping: This is used to map to the Spring MVC controller method.
- @ResponseBody: Used to bind the HTTP response body with a domain object in the return type.
Now, our controller is ready. Let’s run our application inside the DemoApplication.java file. There is no need to change anything inside the DemoApplication.java file.
Step 4: Run the Spring Boot Application
To run the application click on the green icon as seen in the below image.
After successfully running the application you can see the console as shown in the below image. Your Tomcat server started on port 8989.
Try this Tomcat URL, which is running on http://localhost:8989/hello
Please Login to comment...