ssss我们依旧以SpringBoot官网的官方文档为准学习。Spring Boot Features ==> 7.Developing Web Applications ==> 7.4 Embedded Servlet Container Support
使用Servlet API
1 @WebServlet + @ServletComponentScan
@ServletComponentScan(basePackages = “com.atguigu.webadmin”) :指定原生Servlet组件都放在那里
@WebServlet(urlPatterns = “/my”):效果:===> 直接响应,没有经过Spring的拦截器
@WebServlet(urlPatterns = "/my")
public class MyServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.getWriter().write("6666");
}
}
========================================================================================================
// 指定原生Servlet组件存放地点
@ServletComponentScan(basePackages = "com.atguigu.webadmin")
@SpringBootApplication
public class Boot05WebAdminApplication {
public static void main(String[] args) {
SpringApplication.run(Boot05WebAdminApplication.class, args);
}
}
ssss结果:sdsdsdsdsss
2 @WebFilter + @ServletComponentScan
@Slf4j
// 拦截静态资源,单 * 是Servlet写法,** 是SpringBoot写法