Introduction
In this chapter, we will guide you through the process of creating and setting up your first Spring Boot application using IntelliJ IDEA and Spring Initializr. IntelliJ IDEA is a powerful and popular Integrated Development Environment (IDE) that offers comprehensive support for Spring Boot, making it easier for developers to build and manage their applications efficiently. We will use the free Community Edition of IntelliJ IDEA to create and import a Spring Boot project using Spring Initializr.
Step 1: Install IntelliJ IDEA (Free Community Edition)
-
Download IntelliJ IDEA Community Edition:
- Go to the JetBrains website.
- Download the Community Edition (free) of IntelliJ IDEA.
-
Install IntelliJ IDEA:
- Follow the installation instructions specific to your operating system (Windows, macOS, or Linux).
Step 2: Create a New Spring Boot Project using Spring Initializr
-
Open Spring Initializr:
- Navigate to Spring Initializr in your web browser.
-
Configure Project Metadata:
- Group:
com.company
- Artifact:
first-springboot-app
- Name:
Demo
- Description:
First Spring Boot App
- Package name:
com.company.app
- Packaging:
Jar
- Java Version:
17
(or the latest version available)
- Group:
-
Select Dependencies:
- Add the following dependencies:
- Spring Web
- Spring Boot DevTools (optional for hot reloading)
- Add the following dependencies:
-
Generate and Download:
- Click the "Generate" button to download the project as a ZIP file.
Step 3: Import the Project into IntelliJ IDEA
-
Open IntelliJ IDEA:
- Launch IntelliJ IDEA from your installed applications.
-
Import the Project:
- On the welcome screen, click "Open or Import".
- Navigate to the directory where you downloaded the Spring Initializr ZIP file.
- Select the ZIP file and click "Open".
- IntelliJ IDEA will unzip the file and import the project.
-
Configure Maven (if needed):
- IntelliJ IDEA will automatically detect the Maven build file (
pom.xml
) and import the project. - If prompted, confirm any necessary Maven configurations.
- IntelliJ IDEA will automatically detect the Maven build file (
Step 4: Explore the Project Structure
- Project Structure:
- Once the project is imported, you will see the following structure in the Project Explorer:
src/main/java
: Contains your application source code.src/main/resources
: Contains application properties and other resources.src/test/java
: Contains test cases for your application.pom.xml
: Maven configuration file.
- Once the project is imported, you will see the following structure in the Project Explorer:
Step 5: Run Your Spring Boot Application
-
Open Application Class:
- Navigate to the main application class (annotated with
@SpringBootApplication
).
- Navigate to the main application class (annotated with
-
Run the Application:
- In IntelliJ IDEA, right-click the main application class and select "Run ‘DemoApplication’".
- Alternatively, open a terminal, navigate to the project directory, and run
mvn spring-boot:run
.
-
Verify the Application:
- Open a web browser and go to
http://localhost:8080
. - You should see the default Spring Boot welcome page.
- Open a web browser and go to
Conclusion
In this chapter, you have learned how to set up your development environment, create a new Spring Boot project using Spring Initializr, import it into IntelliJ IDEA, explore the project structure, and run your first Spring Boot application. These foundational steps are essential for starting your journey with Spring Boot development. In the next chapter, we will delve deeper into the core concepts and features of Spring Boot.