SpringBoot use interceptor / Servlet / Filter

A, SoringBoot use interceptors

SpringMVC use of interceptors, need to define the interceptor, and then register it through configuration files

In SpringBoot project, the content previously configured in the configuration file, now embodied in a class

This class needs to inherit WebMvcConfigurationSupport class and use @Configuration notes represent the class as a class configuration

1, the interceptor is defined as follows:

  

2, the defined interceptor registration and set blocking rules, as follows:

  

On the test, I do not tested, I stole chart notes, self-test

Two, Spring Boot used in Servlet

1, annotation mode

  Usually 3.0 version of it, Servlet3.0 version only supports annotation mode, if version 2.5, can only use the configuration file mode

  Inherit HttpServlet, rewrite doGet and doPost methods, the use of @WebServlet annotation on the class

  Add @ServletComponentScan on the inlet categories: scanning annotations

2, configuration, and mode

  Does not support annotation mode, you can only use class configuration mode

  Defined Servlet, inherited HttpServlet, rewrite doGet and doPost methods

  Configuration class defined as follows:

   

Three, Spring Boot use Filter

Use Servlet Filter and use similar Spring Boot, the subject is divided version supports two ways

1, annotation mode

  Implement the Filter interface, defined using the Filter @WebFilter comment

    

  Add @ServletComPonentScan annotations on import category, scan registration, support wildcards way

2. configuration

  Filter as defined above

  Configuration class also registered a new name, sorta

    

Used in which intercepted a bit more, to understand the rest of the steps are simple and straightforward.

 

Guess you like

Origin www.cnblogs.com/msi-chen/p/10973312.html