springboot Actual Warfare Registered filter s and listener s

Posted by PeeJay on Thu, 16 Jul 2020 17:00:45 +0200

Application Scenarios

There are special processes in your project that require filters and listeners, such as the spring Framework Character Filter CahracterEncoding Filter.

code implementation


@WebFilter(urlPatterns = "/*",description = "custom filter")
public class MyFilter implements Filter {
    private final Logger _logger = LoggerFactory.getLogger(this.getClass());
    public void init(FilterConfig filterConfig) throws ServletException {
        _logger.info("MyFilter init ...");

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        _logger.info("Handle filter business ...");

    public void destroy() {
        _logger.info("MyFilter destroy ...");


public class MyListener implements ServletContextListener {
    private final Logger _logger = LoggerFactory.getLogger(this.getClass()) ;
    public void contextInitialized(ServletContextEvent servletContextEvent) {
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

Program Entry SpringBootFilterListenerApplication.java

public class SpringBootFilterListenerApplication {
    public static void main(String[] args) {

Result Display

Project Structure Diagram

Historical Articles

Getting Started with SpringBoot

Summary of articles about springboot in action

springboot Actual Read Profile

springboot Combat jsp Template Engine

springboot Actual Combat freemarker Template Engine

springboot Actual Warfare Register Custom Servlet

Topics: SpringBoot Java Spring JSP