如果不想用@SpringBootApplication,那么可以用@EnableAutoConfiguration 和@ComponentScan替代@SpringBootApplication
詳情可見官方文檔:
https://docs.spring.io/spring-boot/docs/2.0.2.RELEASE/reference/htmlsingle/#boot-documentation

一般寫法如上圖,因為@SpringBootApplication
是一個集合的注解,主要應用三個重點注解@SpringBootConfiguration、@EnableAutoConfiguration、@ComponentScan
,查看源碼


所以可以寫成實例:

