问:有了springMVC,为什么还要用servlet?有了servlet3的注解,为什么还要使用ServletRegistrationBean注入的方式?使用场景:在有些场景下,比如我们要使用hystrix-dashboard,这时候就需要注入HystrixMetricsStr ...
问:有了springMVC,为什么还要用servlet?有了servlet3的注解,为什么还要使用ServletRegistrationBean注入的方式?
使用场景:在有些场景下,比如我们要使用hystrix-dashboard,这时候就需要注入HystrixMetricsStreamServlet(第三方的servlet),该servlet是hystrix的组件。
一、代码
1、TestServlet(第一个servlet)
1 package com.xxx.secondboot.servlet; 2 3 import java.io.IOException; 4 5 import javax.servlet.ServletException; 6 import javax.servlet.http.HttpServlet; 7 import javax.servlet.http.HttpServletRequest; 8 import javax.servlet.http.HttpServletResponse; 9 10 public class TestServlet extends HttpServlet {11 12 private static final long serialVersionUID = -4619665430596950563L;13 14 @Override15 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {16 System.out.println("zhaojigang servlet");17 }18 19 @Override20 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {21 this.doGet(req, resp);22 }23 }
原标题:第二十四章 springboot注入servlet
关键词:Spring
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。