@WebServlet(name="FirstServlet" ,urlPatterns="/first") public class FirstServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("执行了"); } }
编写启动类
增加注解 @ServletComponentScan //在springboot启动时会扫描websevlet的路径,并将该类实例化
/** * SpringBoot 启动类 * @SpringBootApplication 是springboot的启动类 * 启动器存放的位置:启动器可以和controller位于同一个包下或者上一个包下。 不能同级的包 */ @SpringBootApplication @ServletComponentScan //在springboot启动时会扫描websevlet的路径,并实例化 public class App { public static void main(String[] args) { SpringApplication.run(App.class, args); } }
编写一个类同样继承HttpServlet
重写doGet方法
在该方法中加入注解 @Bean
/**
原文链接:https://www.cnblogs.com/net-safe/p/13528101.html