spring-boot 如何服务于特定的 url?
How does spring-boot able to serve specific url?
根据我之前的经验:
- 当使用纯
servlet
时,我们定义 servlet 以便它为匹配特定 url 的请求提供服务。
- 在使用
struts2
时,我们定义了一个过滤器,以便它为匹配特定 url 的请求提供服务。
- 在传统 xml 配置样式中使用
springMVC
时,我们定义了一个调度程序 servlet,以便它为匹配特定 url 的请求提供服务。
但是 spring-boot
:
似乎没有明确定义 servlet 或过滤器。但它仍然可以提供特定的网址。
问题是:
- 还在用servlet吗?如果是,它如何在不显式定义 servlet 或过滤器的情况下提供 url?
其他相关问题 (基于评论提示):
SpringBootServletInitializer
的实现似乎会在部署时调用,但谁来调用它?
正如您在 中看到的详细信息,在启动时,在初始化嵌入式服务器时(默认情况下 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);
}
}
根据我之前的经验:
- 当使用纯
servlet
时,我们定义 servlet 以便它为匹配特定 url 的请求提供服务。 - 在使用
struts2
时,我们定义了一个过滤器,以便它为匹配特定 url 的请求提供服务。 - 在传统 xml 配置样式中使用
springMVC
时,我们定义了一个调度程序 servlet,以便它为匹配特定 url 的请求提供服务。
但是 spring-boot
:
似乎没有明确定义 servlet 或过滤器。但它仍然可以提供特定的网址。
问题是:
- 还在用servlet吗?如果是,它如何在不显式定义 servlet 或过滤器的情况下提供 url?
其他相关问题 (基于评论提示):
SpringBootServletInitializer
的实现似乎会在部署时调用,但谁来调用它?
正如您在 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);
}
}