@EnableWebSecurity在春天有什么用处 [英] What is the use of @EnableWebSecurity in spring

查看:3625
本文介绍了@EnableWebSecurity在春天有什么用处的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 spring docs


将此注释添加到 @配置类,通过扩展<$ c $,可以在任何 WebSecurityConfigurer 或更多
中定义Spring
安全配置c> WebSecurityConfigurerAdapter 基类和
重写单个方法:

Add this annotation to an @Configuration class to have the Spring Security configuration defined in any WebSecurityConfigurer or more likely by extending the WebSecurityConfigurerAdapter base class and overriding individual methods:

或者这个 @EnableWebSecurity 描述,用于在我们的项目中启用SpringSecurity。

Or As this @EnableWebSecurity depicts, is used to enable SpringSecurity in our project.

但我的问题是,即使我没有使用 @EnableWebSecurity 注释我的任何类,仍然是应用程序提示输入用户名和密码。(默认行为)

But my question is that even if I don't annotate any of my class with @EnableWebSecurity still the application prompting for username and password.(default behaviour)

所以我收到与 @EnableWebSecurity 相同的行为 @EnableWebSecurity

So I am receiving the same behaviour with @EnableWebSecurity and without @EnableWebSecurity.

有人可以解释这个注释究竟是什么?

Can someone please explain what exactly is this annotation for?

推荐答案

@EnableWebSecurity 是标记注释。它允许Spring找到(它是 @Configuration ,因此, @Component )并自动将类应用于全局 WebSecurity

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.


如果我没有使用<注释我的任何课程code> @EnableWebSecurity 仍然是应用程序提示输入用户名和密码。

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

  • SpringBootWebSecurityConfiguration;
  • FallbackWebSecurityAutoConfiguration;
  • WebMvcSecurityConfiguration.

仔细考虑它们,关闭所需的配置或覆盖其行为。

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

这篇关于@EnableWebSecurity在春天有什么用处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆