springboot配置Filter的两种方法
生活随笔
收集整理的這篇文章主要介紹了
springboot配置Filter的两种方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、使用注解
1. 假設Filter類的路徑為com.sanro.filter
2. 自動掃描配置如下
@Slf4j @EnableScheduling @ServletComponentScan(basePackages = {"com.sanro.filter"}) //這一句完成了配置,Springboot的”懶理念“真的厲害。 @SpringBootApplication public class Application {public static void main(String[] args) {SpringApplication.run(Application.class, args);log.debug("rest server start success.");} }二、手動配置
1. Filter類
@Slf4j @Component public class AuthFilter implements Filter {@Overridepublic void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {log.debug("start to auth request validate...111");HttpServletRequest req = (HttpServletRequest) request;String token = req.getHeader("token");if (token != null) {// :TODO check tokenlog.info("auth success");chain.doFilter(request, response);} else {log.err("auth failed");}} }?
2. Filter配置類
?
轉載于:https://www.cnblogs.com/yoyotl/p/10853499.html
總結
以上是生活随笔為你收集整理的springboot配置Filter的两种方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JS笔记(20): JS中的同步编程和异
- 下一篇: Android build.gradle