How to Create a Spring Boot 3 Project in Spring Tool Suite (STS) | Build Spring Boot 3 REST API in STS
🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
YouTube Video
We recommend watching the YouTube video below to learn how to create a Spring Boot project in Spring Tool Suite (STS) IDE using Spring Initializr and build Spring Boot REST API:
Why Use Spring Tool Suite (STS)?
- Built for Spring: It’s tailored for Spring development with pre-installed plugins for Spring Boot.
- Simplifies Development: Comes with tools like Spring Initializr integration, autocompletion, and debugging support.
- Lightweight and Free: A focused IDE for Spring applications that is completely free.
Prerequisites
Before you begin, ensure the following are installed:
Java Development Kit (JDK 17 or higher):
Spring Boot 3 requires Java 17 or later.Spring Tool Suite (STS):
Download the latest version of STS from https://spring.io/tools. Install it like any other application and ensure it’s working correctly.
Step 1: Create a Spring Boot 3 Project in STS
Open STS: Launch Spring Tool Suite and select a workspace where your projects will be stored.
Create a New Project:
- Go to File > New > Spring Starter Project.
- Alternatively, click the Spring Starter Project button on the toolbar.
Configure the Project:
- Project Name: Enter a name (e.g.,
springboot3-rest-api). - Type: Select Maven (recommended).
- Group ID: Enter your package group (e.g.,
com.example). - Artifact ID: Enter your project artifact name (e.g.,
springboot3-rest-api). - Java Version: Select 17 or later.
- Click Next.
- Project Name: Enter a name (e.g.,
Add Dependencies:
- Select the following dependencies:
- Spring Web: To build REST APIs.
- Click Finish.
- Select the following dependencies:
STS will automatically generate the project structure and download the required dependencies.
Step 2: Explore the Project Structure
Once the project is created, you’ll see the following structure:
springboot3-rest-api/
├── src/
│ ├── main/
│ │ ├── java/com/example/springboot3restapi/
│ │ │ └── Springboot3RestApiApplication.java
│ │ └── resources/
│ │ ├── application.properties
│ ├── test/
│ └── java/
├── pom.xml
- Springboot3RestApiApplication.java: The main class containing the entry point for your application.
- application.properties: Configuration file for application settings.
- pom.xml: The Maven file that manages your project’s dependencies.
Step 3: Build a Simple REST API
Create a REST Controller:
- Right-click on the
src/main/java/com/example/springboot3restapi/folder. - Select New > Class and name it
HelloController.
- Right-click on the
Add Code to the Controller:
- Open the
HelloController.javafile and add the following code:package com.example.springboot3restapi; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @GetMapping("/") public String sayHello() { return "Welcome to Spring Boot 3!"; } }
- Open the
Step 4: Run the Spring Boot Application
Run the Application:
- Open the
Springboot3RestApiApplication.javafile. - Right-click on the file and select Run As > Spring Boot App.
- Open the
Verify the Application:
- After the application starts, the console will display logs indicating that Tomcat has started on port
8080. - Open your browser and navigate to:
http://localhost:8080/ - You should see the response:
Welcome to Spring Boot 3!
- After the application starts, the console will display logs indicating that Tomcat has started on port
Step 5: Customize Application Properties (Optional)
You can modify the application.properties file in the src/main/resources/ folder to customize your application settings. For example:
- Change the server port:
server.port=8081
Step 6: Test the REST API
You can test the REST API using the following methods:
- Browser: Open your browser and go to
http://localhost:8080/. - Postman: Use Postman to send a GET request to
http://localhost:8080/. - cURL: Run this command in the terminal:
curl http://localhost:8080/
Conclusion
Congratulations! You’ve successfully created a Spring Boot 3 project in Spring Tool Suite (STS) and built a simple REST API. This setup provides a solid foundation for creating robust Java applications. As you gain confidence, you can expand your application by adding more endpoints, services, and advanced features. Happy coding!
My Top and Bestseller Udemy Courses. The sale is going on with a 70 - 80% discount. The discount coupon has been added to each course below:
Build REST APIs with Spring Boot 4, Spring Security 7, and JWT
[NEW] Learn Apache Maven with IntelliJ IDEA and Java 25
ChatGPT + Generative AI + Prompt Engineering for Beginners
Spring 7 and Spring Boot 4 for Beginners (Includes 8 Projects)
Available in Udemy for Business
Building Real-Time REST APIs with Spring Boot - Blog App
Available in Udemy for Business
Building Microservices with Spring Boot and Spring Cloud
Available in Udemy for Business
Java Full-Stack Developer Course with Spring Boot and React JS
Available in Udemy for Business
Build 5 Spring Boot Projects with Java: Line-by-Line Coding
Testing Spring Boot Application with JUnit and Mockito
Available in Udemy for Business
Spring Boot Thymeleaf Real-Time Web Application - Blog App
Available in Udemy for Business
Master Spring Data JPA with Hibernate
Available in Udemy for Business
Spring Boot + Apache Kafka Course - The Practical Guide
Available in Udemy for Business
Comments
Post a Comment
Leave Comment