Spring Boot Tutorial

Spring Boot - Software Setup and Configuration (STS/Eclipse/IntelliJ)

Prerequisite (Spring Core Concepts)

Spring Boot Core

Spring Boot with REST API

Spring Boot with Database and Data JPA

Spring Boot with Kafka

Spring Boot with AOP

How to Create and Setup Spring Boot Project in Spring Tool Suite?

Spring Tool Suite (STS) is an IDE specifically tailored for the development of Spring applications. It's built on top of Eclipse and offers first-class support for Spring Boot. Setting up a Spring Boot project in STS is incredibly easy due to its direct integration with Spring Initializr.

Here's how you can create and set up a Spring Boot project in STS:

1. Open Spring Tool Suite:

Start STS. If you don't have it installed, you can download it from the official Spring website.

2. Create a New Spring Starter Project:

  • Go to File -> New -> Spring Starter Project. This will launch the Spring Initializr from within STS.
  • In the New Spring Starter Project dialog:
    • Name: Provide the name for your project.
    • Group: Typically a reverse domain name (e.g., com.example).
    • Artifact: A name for your project artifact, usually the same as the project name.
    • Description: Optional description for your project.
    • Package: The base package for your project.
    • Packaging: Choose between Jar or War (typically Jar for most Spring Boot projects).
    • Java Version: Select the Java version you want to use.
    • Language: Choose between Java, Kotlin, or Groovy.
    • Version: Select the desired Spring Boot version.
    • Click Next.

3. Choose Dependencies:

The next screen allows you to select the dependencies for your project. For a basic web application:

  • Under the "Web" section, select Spring Web (This provides the tools needed for making web applications).
  • Add any other dependencies you need for your project. For example, Spring Data JPA for database access, Thymeleaf for template rendering, etc.
  • Once you've selected your dependencies, click Next.

4. Review and Finish:

  • The next screen will give you a summary of the options you've selected.
  • Click Finish, and STS will generate your project.

5. Explore the Project:

Once STS has generated your project, you can explore its structure in the Project Explorer pane:

  • src/main/java: Contains the Java code. You'll find the main application file here with the @SpringBootApplication annotation.
  • src/main/resources: Contains resources like the application.properties or application.yml configuration file.
  • src/test/java: Contains test files.

6. Run Your Application:

  • Navigate to the main application file (the one with the @SpringBootApplication annotation).
  • Right-click on the file.
  • Select Run As -> Spring Boot App.

Your application will start, and you'll see logs in the console indicating the embedded Tomcat server is running.

7. Development:

From here, you can proceed to develop your Spring Boot application. Create controllers, services, repositories, and more as required. Configure your application using the application.properties or application.yml files.

With STS, you have a dedicated environment for Spring development, which provides built-in features like Boot Dashboard, quick code templates, and more, all aimed at increasing productivity while working with Spring projects.

  1. Setting up a basic Spring Boot web application in STS:

    • Description: Set up a basic Spring Boot web application in STS with a controller and a simple view.
    • Code:
      @SpringBootApplication
      public class MyApplication {
      
          public static void main(String[] args) {
              SpringApplication.run(MyApplication.class, args);
          }
      }
      
  2. Configuring application properties in Spring Boot STS project:

    • Description: Configure application properties, such as server port or database connection, in a Spring Boot project in STS.
    • Code:
      # src/main/resources/application.properties
      server.port=8080
      spring.datasource.url=jdbc:mysql://localhost:3306/mydb
      
  3. Creating a Spring Boot RESTful service in Spring Tool Suite:

    • Description: Create a simple RESTful service in a Spring Boot project within STS.
    • Code:
      @RestController
      public class HelloController {
      
          @GetMapping("/hello")
          public String hello() {
              return "Hello, Spring Boot!";
          }
      }
      
  4. Setting up a Spring Boot MVC application in Spring Tool Suite:

    • Description: Set up a Spring Boot MVC application in STS with controllers, views, and templates.
    • Code:
      @Controller
      public class HomeController {
      
          @GetMapping("/home")
          public String home() {
              return "index";
          }
      }