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

Spring Boot - Starters

In Spring Boot, "starters" are a set of convenient dependency descriptors that you can include in your application. The primary goal of the starters is to reduce boilerplate code, provide an easier way to set up an application, and improve the overall development experience.

When you include a Spring Boot starter dependency in your project, it automatically provides necessary libraries and configurations to make that specific aspect of your application work seamlessly. This means you don't have to hunt down individual dependencies or worry about compatibility between versions.

Here's an overview of some of the commonly used Spring Boot starters:

  1. Web & RESTful applications:

    • spring-boot-starter-web: Includes everything you need to build web applications, including RESTful web services using Spring MVC. It also includes Tomcat as the default embedded servlet container.
  2. Data Access:

    • spring-boot-starter-data-jpa: Makes it easy to work with relational databases using Hibernate and Spring Data JPA.
    • spring-boot-starter-data-mongodb: If you're using MongoDB as your NoSQL store, this starter will be helpful.
    • spring-boot-starter-jdbc: Simplifies database connectivity using JDBC.
  3. Messaging:

    • spring-boot-starter-activemq: Integrates ActiveMQ for JMS messaging.
    • spring-boot-starter-rabbitmq: If you're working with RabbitMQ for messaging, this starter can be beneficial.
  4. Security:

    • spring-boot-starter-security: Provides authentication, authorization, and other security features for your Spring Boot application.
  5. Actuator (Production ready features):

    • spring-boot-starter-actuator: Provides features like monitoring and tracing to your application, so you can monitor its health and other metrics.
  6. Template Engines:

    • spring-boot-starter-thymeleaf: Integrates Thymeleaf for view templates.
    • spring-boot-starter-mustache: Incorporates Mustache templating engine.
    • spring-boot-starter-freemarker: For those who prefer FreeMarker templates.
  7. Batch Processing:

    • spring-boot-starter-batch: For building batch applications using Spring Batch.
  8. WebSocket:

    • spring-boot-starter-websocket: Enables WebSocket functionality in your application.
  9. Testing:

    • spring-boot-starter-test: Provides essential libraries for testing your application, like JUnit, Hamcrest, and Mockito among others.
  10. Caching:

    • spring-boot-starter-cache: Enables easy caching support in the application.

This is just a small selection of available starters. There are many others for different technologies and integrations. The primary benefit of using starters is to keep your Maven or Gradle build file clean and to ensure that you are getting a set of libraries that are known to work well together.

  1. Configuring and customizing starters in Spring Boot:

    • Description: Starters in Spring Boot are a convenient way to include sets of dependencies and configurations for specific purposes. Configure and customize starters based on your project requirements.
    • Code:
      <!-- Example configuring and customizing starters in Spring Boot -->
      <dependencies>
          <dependency>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-data-jpa</artifactId>
          </dependency>
          <!-- Other dependencies and custom configurations -->
      </dependencies>
      
  2. Commonly used starters in Spring Boot:

    • Description: Spring Boot provides a variety of commonly used starters to simplify project setup. Examples include spring-boot-starter-web, spring-boot-starter-data-jpa, and spring-boot-starter-test.
    • Code:
      <!-- Example using commonly used starters in Spring Boot -->
      <dependencies>
          <dependency>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-web</artifactId>
          </dependency>
          <!-- Other commonly used starters -->
      </dependencies>
      
  3. Creating custom starters in Spring Boot:

    • Description: Create custom starters to encapsulate a set of dependencies and configurations. This promotes code reuse and consistency across multiple projects.
    • Code:
      <!-- Example creating a custom starter in Spring Boot -->
      <dependencies>
          <dependency>
              <groupId>com.example</groupId>
              <artifactId>my-custom-starter</artifactId>
              <version>1.0.0</version>
          </dependency>
          <!-- Other dependencies -->
      </dependencies>
      
  4. Dependency management with Spring Boot starters:

    • Description: Spring Boot starters handle dependency management by providing curated sets of dependencies with predefined versions. This ensures compatibility and simplifies project configuration.
    • Code:
      <!-- Example dependency management with Spring Boot starters -->
      <dependencies>
          <dependency>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-data-jpa</artifactId>
          </dependency>
          <!-- Other dependencies with managed versions -->
      </dependencies>
      
  5. Starter vs. Starter Parent in Spring Boot projects:

    • Description: While starters provide predefined sets of dependencies, the spring-boot-starter-parent is a special POM that configures common settings for Spring Boot projects. Both can be used, with the parent POM offering more comprehensive project configuration.
    • Code:
      <!-- Example using both Starter and Starter Parent in Spring Boot -->
      <parent>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-parent</artifactId>
          <version>2.7.0</version>
      </parent>
      <dependencies>
          <dependency>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-web</artifactId>
          </dependency>
          <!-- Other dependencies -->
      </dependencies>
      
  6. Spring Boot web starters and their features:

    • Description: Spring Boot web starters simplify the development of web applications. Examples include spring-boot-starter-web, spring-boot-starter-data-jpa, and spring-boot-starter-thymeleaf.
    • Code:
      <!-- Example using Spring Boot web starters -->
      <dependencies>
          <dependency>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-web</artifactId>
          </dependency>
          <!-- Other web-related starters -->
      </dependencies>
      
  7. Data access starters in Spring Boot:

    • Description: Spring Boot provides data access starters for different persistence technologies, such as JPA, MongoDB, and JDBC. Use them to quickly set up data access in your application.
    • Code:
      <!-- Example using Spring Boot data access starters -->
      <dependencies>
          <dependency>
              <groupId>org.springframework.boot</groupId>
              <artifactId>spring-boot-starter-data-jpa</artifactId>
          </dependency>
          <!-- Other data access starters -->
      </dependencies>