Spring boot整合Servlet
1 @WebServlet(name="FirstServlet",urlPatterns="/first") 2 public class FirstServlet extends HttpServlet { 3 @Override 4 protected void doGet(HttpServletRequest req, HttpServletResponse resp) 5 throws ServletException, IOException { 6 System.out.println("FirstServlet.........."); 7 8 } 9 10 } 11 12 @SpringBootApplication 13 @ServletComponentScan //在spring boot启动时会扫描@WebServlet,并将该类实例化 14 public class App { 15 16 public static void main(String[] args) { 17 SpringApplication.run(App.class, args); 18 19 } 20 21 }
public class SecondServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("secondServlet........."); } } @SpringBootApplication public class App2 { public static void main(String[] args) { SpringApplication.run(App2.class, args); } @Bean public ServletRegistrationBean getBean(){ ServletRegistrationBean bean=new ServletRegistrationBean(new SecondServlet()); bean.addUrlMappings("/second"); return bean; } }
--菜是原罪,所以,努力奔跑吧!

浙公网安备 33010602011771号