REST API with Spring Boot | Lesson 1 | Spring Initializr


You’ll learn,

  • How to use Spring Initializr to create a project.

  • Spring starter dependencies.

  • Discuss the content i.e each and every line, of the generated build file.


Project setup


Let’s take a look at project set up. That is mainly creating the build file. Often times dependencies could be tricky, there are so many external libraries and selecting versions that should be compatible with each other can be difficult at times.

But there’s a one stop shop for all the dependency requirements of a Spring Boot project. That’s the Spring Boot Starters. All you have to do is select a few starter dependencies according the type of project and the starter dependencies will take care of the rest.

You can find a list of Spring Boot Starters and a link to each of the build files here

So for example, if you are building a REST API or a web project, you would add the spring-boot-starter-web dependency to your project and if you take a look at the build file, you can see all the other dependencies it includes. And if you want to use spring data jpa, you would add the spring-boot-starter-data-jpa dependency.


The Build File


    plugins {
        id 'org.springframework.boot' version '2.4.4'
        id 'io.spring.dependency-management' version '1.0.11.RELEASE'
        id 'java'
    }

    group = 'com.example'
    version = '0.0.1-SNAPSHOT'
    sourceCompatibility = '1.8'

    repositories {
        mavenCentral()
    }

    dependencies {
        implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
        implementation 'org.springframework.boot:spring-boot-starter-web'
        runtimeOnly 'com.h2database:h2'
        testImplementation 'org.springframework.boot:spring-boot-starter-test'
    }

    test {
        useJUnitPlatform()
    }

Links


Spring Initializer website: https://start.spring.io

Spring boot starters:

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#using-boot-starter

https://github.com/spring-projects/spring-boot/tree/master/spring-boot-project/spring-boot-starters


The Spring Initializr UI shown in the video above has been updated, if you want to see the latest, checkout this Spring Initializr tutorial