BookstoreApiApplication.java
Springboot/bookstore-api/src/main/java/com/example/bookstore/BookstoreApiApplication.java
package com.example.bookstore;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* ============================================================================
* 應用程式進入點(Entry Point)
* ============================================================================
* {@code @SpringBootApplication} 是一個「三合一」的組合註解,等同於同時標上:
*
* 1. {@code @Configuration}
* —— 表示此類別可以定義 Spring Bean(用 @Bean 方法)。
*
* 2. {@code @EnableAutoConfiguration}
* —— 啟用「自動設定」:Spring Boot 會掃描 classpath 上有哪些套件,
* 自動完成對應設定。例如:
* - 偵測到 spring-webmvc → 自動設定內嵌 Tomcat 與 DispatcherServlet
* - 偵測到 mysql-connector-j + JPA → 自動設定資料庫連線池與 Hibernate
*
* 3. {@code @ComponentScan}
* —— 自動掃描「本套件(com.example.bookstore)與其所有子套件」中
* 標註 @Component / @Service / @Repository / @RestController
* 的類別,建立成 Bean 並放入 Spring 容器,供依賴注入(DI)使用。
* (這就是為什麼其他類別都必須放在本套件底下的原因!)
* ============================================================================
*/
@SpringBootApplication
public class BookstoreApiApplication {
/**
* main 方法:整個後端服務的啟動起點。
*
* SpringApplication.run() 依序會:
* 1. 建立 Spring 容器(ApplicationContext)
* 2. 掃描並實例化所有 Bean、完成依賴注入
* 3. 啟動內嵌 Tomcat(預設監聽 8080 連接埠)開始接收 HTTP 請求
*/
public static void main(String[] args) {
SpringApplication.run(BookstoreApiApplication.class, args);
}
}
Articoli correlati
DataInitializer.java
DataInitializer.java — java source code from the Springboot learning materials (Springboot/bookstore-api/src/main/java/com/example/bookstore/config/DataInitializer.java).
Leggi l'articolo →SecurityConfig.java
SecurityConfig.java — java source code from the Springboot learning materials (Springboot/bookstore-api/src/main/java/com/example/bookstore/config/SecurityConfig.java).
Leggi l'articolo →AuthController.java
AuthController.java — java source code from the Springboot learning materials (Springboot/bookstore-api/src/main/java/com/example/bookstore/controller/AuthController.java).
Leggi l'articolo →BookController.java
BookController.java — java source code from the Springboot learning materials (Springboot/bookstore-api/src/main/java/com/example/bookstore/controller/BookController.java).
Leggi l'articolo →ApiErrorResponse.java
ApiErrorResponse.java — java source code from the Springboot learning materials (Springboot/bookstore-api/src/main/java/com/example/bookstore/dto/ApiErrorResponse.java).
Leggi l'articolo →AuthResponse.java
AuthResponse.java — java source code from the Springboot learning materials (Springboot/bookstore-api/src/main/java/com/example/bookstore/dto/AuthResponse.java).
Leggi l'articolo →