1.实现httpservlet
@WebServlet("/some") public class SomeServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.getWriter().print("some Servlet"); } }
2.
@SpringBootApplication @ServletComponentScan("com.abc.servlet") // 指定要扫描Servlet的包 public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
----------------------------------------------------------------------------------------------------------------------------
2.5
public class SomeServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.getWriter().print("some Servlet"); } }
在配置类中写
@SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } // 基于JavaConfig方式:适用于Servlet2.5+ // 基于注解方式:适用于Servlet3.0+ @Bean public ServletRegistrationBean<SomeServlet> getServlet() { return new ServletRegistrationBean<>(new SomeServlet(), "/some"); } }