如您在此处详细看到的,在启动时,在初始化嵌入式服务器 (默认情况下为Tomcat)时,Spring Boot 创建并注册
DispatcherServlet为servlet。
然后,像往常一样,Spring会 扫描您自己的类 (包括您
SpringApplication.run()从中调用 的类
),并为控制器设置相应的映射(如果有)。例如
/hello此处的映射:
@RestController@EnableAutoConfigurationpublic class TestSpring { @RequestMapping("/hello") String hello() { return "Hello World!"; } public static void main(String[] args) throws Exception { SpringApplication.run(TestSpring.class, args); }}


