Springboot配置過濾器實(shí)現(xiàn)過程解析
寫一個(gè)繼承類
啟動(dòng)器掃一下
此時(shí)訪問一下頁面就可以觀察到過濾器的信息
代碼
package com.example.demo.Filter;import lombok.extern.slf4j.Slf4j;import javax.servlet.*;import javax.servlet.annotation.WebFilter;@Slf4j@WebFilter(filterName = 'myFilter1', urlPatterns = '/*')public class MyFilter1 implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { log.info(filterConfig.getFilterName() + ' init,過濾器初始化成功!'); } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) { log.info('myFilter1 begin'); try { log.info('業(yè)務(wù)方法執(zhí)行'); chain.doFilter(request, response); } catch (Exception e) { log.error('error!', e); } log.info('myFilter1 end'); } @Override public void destroy() { }}
啟動(dòng)器
package com.example.demo;import org.mybatis.spring.annotation.MapperScan;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.web.servlet.ServletComponentScan;@SpringBootApplication(scanBasePackages = {'com.example'})@MapperScan('com.example.demo.mapper')@ServletComponentScan(basePackages = 'com.example.demo.Filter')public class Demo10Application { public static void main(String[] args) { SpringApplication.run(Demo10Application.class, args); }}
結(jié)果
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. bootstrap select2 動(dòng)態(tài)從后臺(tái)Ajax動(dòng)態(tài)獲取數(shù)據(jù)的代碼2. js select支持手動(dòng)輸入功能實(shí)現(xiàn)代碼3. ASP常用日期格式化函數(shù) FormatDate()4. 網(wǎng)頁中img圖片使用css實(shí)現(xiàn)等比例自動(dòng)縮放不變形(代碼已測(cè)試)5. html中的form不提交(排除)某些input 原創(chuàng)6. CSS3中Transition屬性詳解以及示例分享7. vue使用moment如何將時(shí)間戳轉(zhuǎn)為標(biāo)準(zhǔn)日期時(shí)間格式8. python 如何在 Matplotlib 中繪制垂直線9. jsp文件下載功能實(shí)現(xiàn)代碼10. 開發(fā)效率翻倍的Web API使用技巧
