🎓 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
Spring Boot makes Java application development simple and efficient. With Spring Initializr, you can quickly set up a project, and using the free IntelliJ IDEA Free Community Edition, you can start coding immediately. In this guide, we’ll show you how to create a Spring Boot project, import it into IntelliJ IDEA, and build a simple REST API.
YouTube Video
We recommend watching the YouTube video below to learn how to create a Spring Boot project in IntelliJ IDEA (Free Community Edition) IDE using Spring Initializr and build Spring Boot REST API:
What You’ll Need
Java Development Kit (JDK 23):
Download and install JDK 23 from Oracle or OpenJDK.- Verify the installation:
java -version
- Verify the installation:
IntelliJ IDEA Community Edition:
Download the free version of IntelliJ IDEA from JetBrains.
Step 1: Create a Spring Boot Project with Spring Initializr
Visit Spring Initializr:
Go to Spring Initializr in your web browser.Fill in Project Details:
- Group:
com.example - Artifact:
spring-boot-rest-api - Name:
SpringBootRestApi - Packaging: Jar
- Java Version: 23
- Group:
Add Dependencies:
- Click Add Dependencies and select:
- Spring Web: To build REST APIs.
- Spring Boot DevTools: For hot-reloading during development.
- Click Add Dependencies and select:
Download the Project:
- Click Generate to download the project as a ZIP file.
Extract the ZIP File:
Extract the downloaded project to a folder (e.g.,C:\Projects\SpringBootRestApi).
Step 2: Open the Project in IntelliJ IDEA
Launch IntelliJ IDEA:
- Open IntelliJ IDEA Community Edition.
Open the Project:
- From the IntelliJ welcome screen, click Open.
- Navigate to the folder where you extracted the Spring Boot project and select it.
Wait for Dependencies:
- IntelliJ will automatically detect the
pom.xmlfile (Maven project) and download the necessary dependencies.
- IntelliJ will automatically detect the
Step 3: Explore the Project Structure
Your project will look something like this:
spring-boot-rest-api/
├── src/
│ ├── main/
│ │ ├── java/com/example/springbootrestapi/
│ │ │ └── SpringBootRestApiApplication.java
│ │ └── resources/
│ │ ├── application.properties
├── pom.xml
- SpringBootRestApiApplication.java: The main class for your Spring Boot application.
- application.properties: Configuration file for the application.
- pom.xml: Maven’s configuration file to manage dependencies.
Step 4: Create a Simple REST API
Create a Controller:
- Inside the
com.example.springbootrestapipackage, right-click and select New > Java Class. - Name the class
HelloController.
- Inside the
Add REST API Code:
- Open
HelloController.javaand paste the following code:package com.example.springbootrestapi; 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
Step 5: Run the Application
Run the Application:
- Open the
SpringBootRestApiApplication.javafile. - Right-click and select Run 'SpringBootRestApiApplication'.
- Open the
Verify the API:
- Once the application starts, open your browser and go to:
http://localhost:8080/ - You should see the message:
Welcome to Spring Boot 3!
- Once the application starts, open your browser and go to:
Conclusion
You’ve successfully created a Spring Boot project, imported it into IntelliJ IDEA, and built a REST API. This basic setup can now be expanded to include more features, such as additional endpoints, services, or database connections. 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