spring-boot 如何服务于特定的 url?

How does spring-boot able to serve specific url?

根据我之前的经验:

但是 spring-boot:

似乎没有明确定义 servlet 或过滤器。但它仍然可以提供特定的网址。

问题是:


其他相关问题 (基于评论提示):

正如您在 中看到的详细信息,在启动时,在初始化嵌入式服务器时(默认情况下 Tomcat),Spring引导 创建并注册 DispatcherServlet 作为 servlet。

Spring 然后,像往常一样, 扫描您自己的 类(包括您从中调用 SpringApplication.run() 的那个)并设置相应的映射对于你的控制器,如果你有的话。例如 /hello 的映射在这里:

@RestController
@EnableAutoConfiguration
public class TestSpring {

    @RequestMapping("/hello")
    String hello() {
        return "Hello World!";
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(TestSpring.class, args);
    }

}