What You'll Learn

The video shows you how to generate a Spring Boot application with web and database dependencies.

Let's have a look at the source code that is generated from this process.

The Java source

The tool will generate code in both the src/main and src/test folders. The project structure follows a convention. It is possible to change this but it requires configuration. Spring Boot follows a "convention over configuration" approach. Use the defaults where possible.

The main class

Look in the /src/main folder. The generated code will look similar to this (you may have different package and class names).

package uk.ac.cf.cs.cm6213.tutorialcompanion;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class TutorialCompanionApplication {

    public static void main(String[] args) {
        SpringApplication.run(TutorialCompanionApplication.class, args);
    }

}

In this code, we can see the first use of an annotation.

@SpringBootApplication

This tells Spring Boot that this class is the entry point for the application. Note, how the code invokes the class SpringApplication and passes the class of our generated class. This tells us that we are calling Spring with our own code as a parameter, so that Spring can call it or introspect it.

The test class

A simple test class is also created. This is an empty test, but is enough to test that Spring Boot has loaded correctly as it would fail if the application hasn't started.

The Gradle source

The tool creates an initial build.gradle file.

Examine the file and notice:

Notice also that the tool generates a .gitignore file and the Gradle wrapper files (gradlew, etc). These files are put into source control. This means that the version of Gradle required to build the project is bundled with the project.

This means that a developer can build your code by checking out the project and running

./gradlew build

In this codelab, we have used the Spring Initializr tool to create a first Spring Boot project. In a subsequent codelab, we will run the project using Gradle and the command line.