What is the use of @EnableWebSecurity in spring

前端 未结 3 1507
猫巷女王i
猫巷女王i 2021-02-01 01:51

As per spring docs

Add this annotation to an @Configuration class to have the Spring Security configuration defined in any WebSecurit

3条回答
  •  终归单人心
    2021-02-01 02:50

    The @EnableWebSecurity is a marker annotation. It allows Spring to find (it's a @Configuration and, therefore, @Component) and automatically apply the class to the global WebSecurity.

    If I don't annotate any of my class with @EnableWebSecurity still the application prompting for username and password.

    Yes, it is the default behavior. If you looked at your classpath, you could find other classes marked with that annotation (depends on your dependencies):

    • SpringBootWebSecurityConfiguration;
    • FallbackWebSecurityAutoConfiguration;
    • WebMvcSecurityConfiguration.

    Consider them carefully, turn the needed configuration off, or override its behavior.

提交回复
热议问题