Creating a Spring Boot Project
Creating a Spring Boot project means making the folders and files a new app needs. Spring Initializr is a website that makes the project for you.
The app class
This is the class Initializr makes. The annotation marks it as the app class.
@SpringBootApplication
public class DemoApplication {The main method
The main method hands the app class to Spring.
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}Example
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}Key points
- Spring Initializr is a website that makes a new project.
- You pick Java and Maven on the site.
- You also pick web, so the app can answer browser requests.
- The project has folders for code and files for settings.
- The Java code lives in folders under src.
- An annotation is a note above a class that tells Spring something.
- The annotation on the app class is @SpringBootApplication.
In this example, the annotation marks DemoApplication as the app class. The main method is the entry point of the program. It hands the app class to Spring. Running the class prints the Spring Boot banner with the version.
Note
Gradle is the other build choice, and this course uses Maven only.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What is an annotation?