Spring Boot Filter Implementation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.