问:有了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     @Override
15     protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
16         System.out.println("zhaojigang servlet");
17     }
18 
19     @Override
20     protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
21         this.doGet(req, resp);
22     }
23 }
View Code

相关文章:

  • 2021-07-07
  • 2021-06-10
  • 2021-11-02
  • 2021-09-04
  • 2021-08-12
  • 2021-08-24
  • 2021-10-20
猜你喜欢
  • 2021-05-09
  • 2021-07-18
  • 2022-12-23
  • 2022-01-25
  • 2022-12-23
  • 2021-12-22
  • 2021-11-27
相关资源
相似解决方案