长沙网站建设 个人怎样在百度上免费做广告
目录:
-
- 1、用法介绍
- 2、实例讲解
1、介绍
在SpringBoot项目启动器中添加@ServletComponentScan注解后,SpringBoot在启动时会扫描并注册所有带有@WebServlet(控制器)、@WebFilter(过滤器)、@WebListener(监听器)注解的类。
🌟需要注意
可以任意位置创建类,但是类名的末尾必须包含
servlet
、filter
、listener
中的一个
2、实例讲解
2.1、在入口Application类上加入注解@ServletComponentScan
package com.hui;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;@SpringBootApplication
@ServletComponentScan
public class Application {public static void main(String[] args) {SpringApplication.run(Application.class, args);}
}
2.2、.新建Servlet类,继承HttpServlet并且加入注解
//xxx:自定义 xxxxx:自选路劲
@WebFilter(name=“xxx”,urlPatterns=“xxxxx”)