压测hello world的时候,发现spring mvc比HttpServlet的性能下降20%作用
在spring boot环境下使用HttpServlet如下
1、添加@ServletComponentScan
注解
@ServletComponentScan
@SpringBootApplication
public class HelloK8sApp {
public static void main(String[] args) {
SpringApplication.run(HelloK8sApp.class);
}
}
2、使用@WebServlet
注解HttpServlet类
@WebServlet(value = "/xyz")
public class HelloServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.getOutputStream().write("xyz".getBytes(StandardCharsets.UTF_8));
}
}
Posted in: java基础
Comments are closed.