The package line says which folder the class lives in. The imports bring in two Spring classes. At Spring Boot Application marks this as a Spring Boot app. Main is the normal Java starting point. And Spring Application dot run starts Spring, and the web server.
BookshopApplication.javajava
package com.example.bookshop;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class BookshopApplication { public static void main(String[] args) { SpringApplication.run(BookshopApplication.class, args); }}
An annotation is a label that starts with an at sign. It gives extra information to Spring. At Spring Boot Application does three jobs at once. It marks the class as configuration. It turns on auto configuration, which sets things up based on your dependencies. And it scans this package, to find your other classes.
Let's start the app, with no endpoints at all. We turn on a few extra log lines, so we can see the web server start. Run it. Spring starts Tomcat, a web server, on port eight zero eight zero. And then it says the application has started, in about two seconds.
INFO BookshopApplication : Starting BookshopApplication using Java 17.0.18
INFO BookshopApplication : No active profile set, falling back to 1 default profile:
"default"
INFO TomcatWebServer : Tomcat initialized with port 8080 (http)
INFO StandardService : Starting service [Tomcat]
INFO StandardEngine : Starting Servlet engine: [Apache Tomcat/11.0.27]
INFO TomcatWebServer : Tomcat started on port 8080 (http) with context path '/'
INFO BookshopApplication : Started BookshopApplication in 1.387 seconds
The main class has at Spring Boot Application, and calls Spring Application dot run. That starts Spring, and the Tomcat web server. Next, running the app.