1、编写servlet
@WebServlet(urlPatterns = "/myservlet") //定义请求路径
public class MyServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.getWriter().println("MyServlet");
resp.getWriter().flush();
resp.getWriter().close();
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.doPost(req, resp);
}
}
2、配置扫描路径
@SpringBootApplication //开启spring配置
@ServletComponentScan(basePackages = "com.study.springboot.servlet") //配置扫描路径
public class Springboot11ServletApplication {
public static void main(String[] args) {
SpringApplication.run(Springboot11ServletApplication.class, args);
}
}