如果不想用@SpringBootApplication,那么可以用@EnableAutoConfiguration
和@ComponentScan替代@SpringBootApplication
详情可见官方文档:
https://docs.spring.io/spring-boot/docs/2.0.2.RELEASE/reference/htmlsingle/#boot-documentation
一般写法如上图,因为@SpringBootApplication
是一个集合的注解,主要应用三个重点注解@SpringBootConfiguration、@EnableAutoConfiguration、@ComponentScan
,查看源码
所以可以写成实例: