Spring Boot Filter Implementation
1. Direct configuration of annotation mode
@Component @servletcomponentscan@webfilter (urlpatterns = "/*", FilterName = "Loginfilter") public class Loginfilter Implements filter{}
1, @Component The purpose of this annotation is to give loginfilter to the container to handle. Which means that loginfilter works.
2, @ServletComponentScan This use to scan @webfilter let @webfilter function. Of course, the servlet line tube annotations are also possible.
This @servletcomponentscan is best written on apllication, a generic configuration.
I do not write it on application because there is only one filter.
3, @WebFilter This use is obvious, for what link to do filter, filter name is why.
[Email protected] form configuration
Direct Inheritance Filter
public class Loginfilter implements filter{}
or Inherit Genericfilterbean
public class Loginfilter extends genericfilterbean{}
@SpringBootApplication public class Springrestapplication {public static void main (string[] args) {springapplication. Run (Springrestapplication.class, args); } @Bean Public Filterregistrationbean Filterregistrationbean () {Filterregistrationbean Registrationbean = new FilterR Egistrationbean (); Httpbasicauthorizeattribute httpbasicfilter = new Httpbasicauthorizeattribute (); Registrationbean.setfilter (Httpbasicfilter); list<string> urlpatterns = new arraylist<string> (); Urlpatterns.add ("/user/*"); Registrationbean.seturlpatterns (Urlpatterns); return Registrationbean; } }
Spring Boot Filter Implementation