springboot过滤器配置/** * 基本信息过滤器 * * @author jWX562483 */@EnableConfigurationProperties(DebugProperties.class)@WebFilter(filterName = "InstanceFilter", urlPatterns = "/*") //配置过滤器名称和拦截的路径@Componentpublic class InstanceFilter extends OncePerRequestFilter { //过滤器需要继承接口OncePerRequestFilter private static final Logger logger = LogManager.getLogger(InstanceFilter.class); @Autowired private DebugProperties debugProperties; @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) //继承这个方法 //请求发出后,会匹配过滤器拦截路径,如果匹配成功,则调用这个方法 throws ServletException, IOException { if (debugProperties.isDebug()) { HttpInfoUtils.setLanguage(debugProperties.getLanguage()); HttpInfoUtils.setProjectCode(debugProperties.getProjectCode()); HttpInfoUtils.setUser(JSON.parseObject(debugProperties.getUserInfo(), User.class)); } else { try { HttpInfoUtils.parseAndSetLanguage(); } catch (Exception e) { logger.info(e.getMessage()); } try { HttpInfoUtils.parseAndSetProjectCode(); } catch (Exception e) { logger.info(e.getMessage()); } try { HttpInfoUtils.parseAndSetUserInfo(); } catch (Exception e) { logger.info(e.getMessage()); } } filterChain.doFilter(request, response); //放行 }}