Spring Boot Backend Development Course, Development Environment, Installing IntelliJ on macOS

Spring Boot is a Java-based framework that helps you build RESTful web services quickly and easily. In this course, you will learn backend development using Spring Boot and how to install IntelliJ IDEA for development in a macOS environment. This course covers content from basics to advanced topics.

1. Understanding Spring Boot

Spring Boot is built on top of the Spring framework, and it helps to set up and configure your projects more quickly than traditional Spring projects. This allows developers to write only the code they need, reducing the time spent on repetitive configurations. Spring Boot can flexibly respond to various deployment structures, such as cloud environments and microservices architectures.

1.1 Features of Spring Boot

  • Auto Configuration: Automatically handles common configurations, allowing developers to focus on business logic.
  • Starter Dependency Management: Easily manages necessary libraries through Maven or Gradle.
  • Executor Support: Facilitates asynchronous processing to enhance performance and scalability.
  • Prebuilt Aspects: Quickly develop using pre-made templates.

2. Setting Up the Development Environment

Now we will set up the environment needed to develop a Spring Boot project. Follow the steps below to install IntelliJ IDEA on macOS and set up the JDK.

2.1 Installing the JDK

To develop with Spring Boot, you need the Java Development Kit (JDK). On macOS, you can easily install the JDK via Homebrew.

brew install openjdk@11

Once the installation is complete, set the system environment variables. This will allow the system to recognize the path to the JDK.

echo 'export JAVA_HOME="$(brew --prefix openjdk@11)"' >> ~/.zshrc
source ~/.zshrc

2.2 Installing IntelliJ IDEA

IntelliJ IDEA is one of the most popular Java IDEs. Install it on macOS following the steps below.

2.2.1 Installing via Homebrew

If you already use Homebrew, you can install IntelliJ IDEA Community Edition with the following command.

brew install --cask intellij-idea-community

2.2.2 Direct Download

You can also download and install it directly. Download the IntelliJ IDEA Community Edition from JetBrains’ official website and install it. Once installed, run the program and follow the setup wizard to configure the basic environment.

2.3 Configuring IntelliJ IDEA

When you first start IntelliJ IDEA, you need to install the required plugins and configure the environment. The plugin for Spring Boot is built into the IDE, but you can also install additional plugins if needed.

  1. Run IntelliJ IDEA.
  2. In the main menu, select File > Settings (for macOS, IntelliJ IDEA > Preferences).
  3. Navigate to the Plugins tab and search for and install any necessary additional plugins.

3. Creating a Spring Boot Project

Now let’s create a Spring Boot project in IntelliJ IDEA. This will enable you to start backend development in earnest.

3.1 Creating a New Project

  1. Click New Project in IntelliJ IDEA.
  2. Select Spring Initializr from the left menu.
  3. Set the Project SDK to JDK 11.
  4. Click the Next button to proceed to the next step.
  5. Configure the Group and Artifact. For example, set Group to com.example and Artifact to demo.
  6. Select the necessary libraries under Dependencies. For example, you can choose Spring Web, Spring Data JPA, etc.
  7. Click Finish to create the project.

3.2 Understanding Project Structure

Once the project is created, you need to understand the basic structure of Spring Boot. Typically, the generated project has the following directory structure:

  • src/main/java: The directory where the Java code resides.
  • src/main/resources: The directory containing configuration files (yml, properties) and static resources.
  • src/test/java: The directory where the test code resides.

3.3 Modifying Basic Configuration Files

You can adjust basic settings by modifying the application.properties or application.yml file in the project root directory. Configure database connection information, server ports, etc.

4. Creating Your First Controller

Now let’s create a simple RESTful API to verify that the Spring Boot application is functioning.

4.1 Creating a Hello Controller

package com.example.demo.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @GetMapping("/hello")
    public String hello() {
        return "Hello, Spring Boot!";
    }
}

4.2 Running the Application

After writing the controller, start the application by running the main application class. You can build and run the project by executing the following command in the terminal.

./mvnw spring-boot:run

In your web browser, enter http://localhost:8080/hello to see the message “Hello, Spring Boot!”.

5. Conclusion

Through this course, you learned the basic concepts of Spring Boot, how to install IntelliJ IDEA on macOS, and how to build a simple RESTful API. You gained an understanding of the advantages and strengths of Spring Boot, laying the groundwork for using it in real projects. The next steps should include learning about database integration, security and authentication, testing, and deployment methodologies.

6. References

Please explore the resources below for more in-depth study.

Spring Boot Backend Development Course, Development Environment, 0.5 Sweet Shortcuts to Greatly Enhance Development Convenience and Speed

Spring Boot is a powerful framework for building modern web applications and services. In this course, we will delve into the basic setup for backend development using Spring Boot and some handy shortcuts to enhance development convenience. First, let’s briefly look at the features of Spring Boot.

1. Features of Spring Boot

Spring Boot simplifies the configuration and setup of the Spring framework, helping developers focus on business logic. Here are the main features of Spring Boot:

  • Auto Configuration: Spring Boot automatically handles the necessary configurations for the application.
  • Embedded Server: Applications can be easily run via an embedded server without needing to install a separate server.
  • Dependency Management: Required library dependencies can be simply managed through the POM file.
  • Production-Ready Features: Offers various features for monitoring, metric collection, and more.

2. Setting Up the Development Environment

To start development using Spring Boot, you need to set up an appropriate development environment. The following describes the necessary steps.

2.1 Installing JDK

To use Spring Boot, you must first install the Java Development Kit (JDK). The JDK is a tool that helps you develop Java applications. It is advisable to install version 11 or higher.

java -version

2.2 Choosing an IDE

The most commonly used Integrated Development Environments (IDEs) for Spring Boot development include:

  • IntelliJ IDEA: An IDE that offers powerful features and convenience, optimized for Spring Boot development.
  • Eclipse: An IDE with a wide array of plugins and ecosystem.
  • VSCode: A lightweight, fast editor that supports various programming languages.

2.3 Initializing Spring Boot

To start a Spring Boot project, you can generate a project using Spring Initializr. You can access it through the link below:

Spring Initializr

Fill in the metadata in the project settings and select the necessary dependencies:

  • Project: Maven Project
  • Language: Java
  • Spring Boot: Select the desired version
  • Dependencies: Spring Web, Spring Data JPA, H2 Database, Lombok, etc.

2.4 Managing Dependencies

Open the POM file of the generated project and add the necessary dependencies. Spring Boot’s dependency management features allow you to manage libraries easily.

3. Handy Shortcuts to Enhance Development Convenience and Speed

Let’s explore shortcuts that can be useful in the IDE while developing. These shortcuts will greatly enhance the convenience and productivity of your development environment.

3.1 IntelliJ IDEA Shortcuts

  • Code Completion: Ctrl + Space – Provides automatic code completion.
  • Code Formatting: Ctrl + Alt + L – Automatically arranges the code.
  • Commenting: Ctrl + / – Comments or uncomments the selected code.
  • Finding Methods: Ctrl + F12 – Shows the list of methods in the class.
  • Search Everything: Shift + Shift – Allows searching for files, classes, symbols, etc.

3.2 Eclipse Shortcuts

  • Code Completion: Ctrl + Space – Uses the auto code completion feature.
  • Adding Comments: Ctrl + / – Adds a single-line comment.
  • Finding Errors: Ctrl + . – Finds any occurring errors.
  • Code Cleanup: Ctrl + Shift + F – Applies code formatting.

3.3 VSCode Shortcuts

  • Code Completion: Ctrl + Space – Suggests code snippets and completions.
  • File Navigation: Ctrl + P – Quickly performs file search.
  • Commenting: Ctrl + / – Comments out the selected lines of code.
  • Format Entire Code: Shift + Alt + F – Formats all the code.

4. Conclusion

Backend development using Spring Boot maximizes development convenience due to its various advantages and shortcuts. With the right setup of your development environment and useful shortcuts, you will be able to write code faster and more efficiently. As more advanced development environments and tools emerge, continue to learn and apply them.

Spring Boot Backend Development Course, Development Environment, 0.4 Example Code Repository Location and Asking Questions to the Author via GitHub Issues

1. Introduction

Spring Boot is a Java-based framework that simplifies the Spring framework, providing tools to help developers easily create applications. This course will cover the basics of backend development using Spring Boot and delve into advanced techniques and best practices. The focus is on learning web application development through Spring Boot with hands-on experience in setting up the development environment, writing code, and example projects.

2. Development Environment

To use Spring Boot, the following development environment is required:

2.1 Required Software

  • JDK (Java Development Kit): Spring Boot is developed in Java, so the JDK is necessary. JDK 11 or higher is recommended.
  • IDE (Integrated Development Environment): It is recommended to use an IDE like IntelliJ IDEA, Eclipse, or Spring Tool Suite.
  • Build Tool: You can manage project dependencies using Maven or Gradle.

2.2 Setting Up the Development Environment

  1. Install JDK: Download and install the JDK from the Oracle or OpenJDK website.
  2. Install IDE: Download and install the IDE on your local machine. For example, IntelliJ IDEA can be downloaded from the official website.
  3. Install Maven/Gradle: Follow the installation instructions for your chosen build tool.

3. Creating a Project

Spring Boot projects can be easily created. You can use Spring Initializr to choose the required dependencies and generate a project.

3.1 Using Spring Initializr

Visit Spring Initializr (https://start.spring.io/) to enter the project’s metadata and select the necessary dependencies. Then click the ‘Generate’ button to download the project as a ZIP file.

4. Example Code Repository Location

The example code used in this course is stored on GitHub. You can find it at the following link:

Spring Boot Example Code Repository

The repository includes example code for each lesson and instructions on how to run it. The code is updated periodically, and changes for each version can be viewed in the commit logs.

5. Asking Questions: GitHub Issues

If you have any questions or difficulties during the course, you can ask through the ‘Issues’ section on GitHub. Here are the steps to create an issue:

5.1 Creating an Issue

  1. Go to the repository page and click the ‘Issues’ tab.
  2. Click the ‘New Issue’ button to create a new issue.
  3. Enter the title and content. Describe the issue specifically and include code snippets if necessary.
  4. Click the ‘Submit new issue’ button to submit the issue.

5.2 Notes for Writing Issues

Please follow these guidelines for effective problem-solving:

  • Write a clear title: Create a title that summarizes the content of the issue.
  • Describe the situation: Specifically explain the conditions under which the issue occurred and the methods you attempted.
  • Reproducibility: Provide the necessary information for others to reproduce the issue.

6. Conclusion

This post provided information on setting up the Spring Boot backend development environment and the example code repository. Feel free to ask questions through GitHub issues anytime during the course. In the next session, we will learn about developing RESTful APIs using Spring Boot. Thank you.

Spring Boot Backend Development Course, Development Environment, 0.3 Installing Postman

Setting Up the Development Environment

Spring Boot is a Java-based framework that helps to build Spring applications more easily and quickly. In this tutorial, we will explore how to set up a backend development environment using Spring Boot. This process will include basic development environment setup, as well as how to install Postman at the end.

1. Installing the Java Development Kit (JDK)

To use Spring Boot, you first need to install the JDK. The JDK is a core component of Java, providing the tools necessary to develop and run Java applications.

  • Download the JDK from the official Oracle website (here).
  • Proceed with the installation, keeping in mind the JDK path during the installation process. It typically installs in the Program Files on the C drive.
  • Once the installation is complete, verify that the JDK is installed correctly by entering the command java -version in CMD (Command Prompt).

2. Installing an IDE

You need to install an IDE (Integrated Development Environment) for Spring Boot development. The most commonly used IDEs are IntelliJ IDEA and Eclipse. Both of these IDEs support Spring Boot, and you can choose according to your preference.

  • IntelliJ IDEA
    • Download the Community Edition from the official IntelliJ IDEA website (here).
    • Run the downloaded file to proceed with the installation.
    • Once installed, run IntelliJ IDEA and click ‘Create New Project’ to create a new Spring Boot project.
  • Eclipse
    • Download Eclipse IDE for Enterprise Java Developers from the official Eclipse website (here).
    • Run the installer after downloading to proceed with the installation.
    • Once installed, run Eclipse and create a new project by going to ‘File’ > ‘New’ > ‘Java Project’.

3. Initializing Spring Boot

You can use Spring Initializr to generate the initial project to start a Spring Boot application.

  • Access Spring Initializr in your web browser.
  • Select ‘Maven Project’ or ‘Gradle Project’ under Project.
  • Select ‘Java’ under Language.
  • Choose the desired Spring Boot version under Select the version.
  • Enter the group name for the package in Group and the project name in Artifact.
  • Select the necessary libraries under Dependencies. For example, you can add ‘Spring Web’, ‘Spring Data JPA’, ‘H2 Database’, etc.
  • Click the ‘Generate’ button to download the zip file and extract it.

4. Installing Postman

Postman is one of the most widely used tools for testing APIs and sending requests. It is very useful when building RESTful APIs while developing Spring Boot applications.

  • Visit the official Postman website (here) to download the appropriate version for your operating system.
  • Run the downloaded installer to install Postman.
  • Once installed, run Postman and create a new request.

How to Use Postman

Let’s briefly look at how to send API requests using Postman. First, you can send requests while the Spring Boot application is running properly.

  1. Launch Postman and click the New button at the top to create a new request.
  2. Enter the name of the request in Request Name and select the collection to save the request in Save to.
  3. Select the HTTP method. You can choose GET or POST, for example.
  4. Enter the API endpoint where you want to send the request in the URL. For example, it would look like http://localhost:8080/api/users.
  5. When ready to send the request, click the Send button. You can check the results at the bottom.

Conclusion

In this post, we explained how to set up a development environment for Spring Boot backend development and how to install Postman. The upcoming tutorials will continue to cover how to develop actual applications using Spring Boot. Make sure to follow the configurations explained in this course as you move on to the next steps.

Spring Boot Backend Development Course, Development Environment, 0.2 Creating a Spring Boot 3 Project

0.2 Creating a Spring Boot 3 Project

1. What is Spring Boot?

Spring Boot is a framework for easily building Java-based web applications and RESTful web services. It is an enhanced version of the traditional Spring Framework, helping developers to quickly develop applications with minimal setup and without complex configuration processes.

Spring Boot offers various pre-configured libraries and starter packages, enabling rapid prototyping and simple deployment. By following the ‘Convention over Configuration’ principle, developers can focus more on business logic.

2. Setting Up the Development Environment

To use Spring Boot 3, you need the Java Development Kit (JDK) and either Maven or Gradle. JDK version 17 or higher is required, and it is recommended to use IDEs like IntelliJ IDEA or Eclipse.

2.1 Installing the JDK

  1. JDK Download: Visit the Oracle JDK download page.
  2. Select and download the JDK according to your operating system.
  3. After installation, add the environment variable. For Windows, set JAVA_HOME to the JDK installation path in System Properties -> Advanced System Settings -> Environment Variables.

2.2 Installing the IDE

IntelliJ IDEA has both free and paid versions, and the free Community Edition is sufficient. After downloading and installing, you can add Maven or Gradle as plugins.

3. Creating a Spring Boot 3 Project

Now, let’s create a Spring Boot 3 project. There are two ways to create a project: using Spring Initializr or through an IDE.

3.1 Creating a Project with Spring Initializr

  1. Access Spring Initializr.

  2. Select either Maven Project or Gradle Project for the Project type.

  3. Select Java for the Language.

  4. Choose Spring Boot version 3.0.0 or higher.

  5. Input the Project Metadata, including Group, Artifact, Name, Description, and Package Name.

  6. Select necessary libraries from Dependencies. Add libraries like Web, JPA, H2, etc.

  7. Click the Generate button to download the ZIP file, and then extract it to your desired location.

3.2 Creating a Project through the IDE

  1. Open IntelliJ IDEA and select File > New > Project.
  2. Select Spring Initializr and proceed to the next steps. Set up Group, Artifact, and Dependencies.
  3. Click Finish to create the project.

3.3 Project Structure

The basic structure of the created project is as follows:

  • src
    • main
      • java
        • com
          • example
            • demo
              • DemoApplication.java
              • controller
              • service
              • repository
      • resources
        • application.properties
        • static
        • templates
    • test
      • java

4. Creating a Hello World API

Now let’s create a simple REST API that returns “Hello World”.

4.1 Creating the Controller

Create a file named HelloController.java in the src/main/java/com/example/demo/controller directory and enter the following content:


package com.example.demo.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    @GetMapping("/hello")
    public String hello() {
        return "Hello, World!";
    }
}
            

4.2 Running the Application

  1. Run the application by executing ./mvnw spring-boot:run from the root directory of the project or by clicking the run button in the IDE.
  2. Open a web browser and navigate to http://localhost:8080/hello to see the Hello World message.

5. Connecting to a Database

Now let’s add a simple database connection. We will create a simple CRUD application using the H2 database.

5.1 Adding H2 Database Dependency

Open the pom.xml file and add the following dependency:



    com.h2database
    h2
    runtime

            

5.2 Configuring application.properties

Add the following content to the src/main/resources/application.properties file:


spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=update
            

5.3 Creating the Entity Class

Create a directory named entity under src/main/java/com/example/demo/ and create a file named User.java:


package com.example.demo.entity;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String name;
    private String email;

    // Getters and Setters
}
            

5.4 Creating the Repository Interface

Create a file named UserRepository.java in the src/main/java/com/example/demo/repository directory:


package com.example.demo.repository;

import com.example.demo.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;

public interface UserRepository extends JpaRepository {
}
            

5.5 Creating the Service Class

Create a file named UserService.java in the src/main/java/com/example/demo/service directory:


package com.example.demo.service;

import com.example.demo.entity.User;
import com.example.demo.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

    @Autowired
    private UserRepository userRepository;

    public List getAllUsers() {
        return userRepository.findAll();
    }

    public User saveUser(User user) {
        return userRepository.save(user);
    }
}
            

5.6 Creating UserController

Create a file named UserController.java in the src/main/java/com/example/demo/controller directory:


package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/users")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping
    public List getAllUsers() {
        return userService.getAllUsers();
    }

    @PostMapping
    public User createUser(@RequestBody User user) {
        return userService.saveUser(user);
    }
}
            

6. Running and Testing the Application

Now it’s time to run the application and test the API using Postman or cURL.

6.1 Running the Application

Run the application.

6.2 Testing the API

Use a GET request to retrieve all user information:


GET http://localhost:8080/users
            

Use a POST request to create a new user:


POST http://localhost:8080/users
Content-Type: application/json

{
    "name": "John Doe",
    "email": "john@example.com"
}
            

Conclusion

In this tutorial, we learned how to create a simple backend application using Spring Boot. Thanks to the advanced features of Spring Boot, application development has become much easier. In the next tutorial, we will cover security, testing, and deployment.