您现在的位置是: 首页 > 后端开发 SpringBoot 2.x Security security.basic.enabled=false 失效问题解决
SpringBoot 2.x Security security.basic.enabled=false 失效问题解决
2020-06-10 【后端开发】 5176人已围观 8726次浏览
简介SpringBoot 2.x Security security.basic.enabled=false 失效问题解决
在将一个 SpringBoot 1.x 的项目升级到 2.x 的过程中,测试时发现之前在 1.x 项目中,关闭 Security 验证的配置不可用了
security:
basic:
enabled: false
查看文档发现,这样的配置在 2.0+ 之后就无法使用了,在 SpringBoot 2.x 的项目中,需要通过代码去配置
也就是继承 WebSecurityConfigurerAdapter 类,并重写其中的 configure(HttpSecurity http) 方法
我们可以新建一个类叫做 SecurityConfig,并加入以下代码
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.anyRequest().permitAll().and().logout().permitAll();//配置不需要登录验证
}
}
之后重新运行 SpringBoot 项目,访问任意接口,就都不需要使用 Security 自动生成的账号密码登录了
很赞哦! (0)
相关文章
- SpringBoot 启动测试时出现提示 Test class should have exactly one public zero-argument constructor
- Laravel项目出现could not be opened: failed to open stream: Permission denied
- SpringBoot 2.x 文件上传出现 The field file exceeds its maximum permitted size of 1048576 bytes
- mac idea spring boot 启动慢
- Error in execution; nested exception is io.lettuce.core.RedisCommandExecutionException: ERR DISABLE You can't write or read against a disable instance
- PHP 在执行 composer install 时出现提示 PHP Fatal error: Allowed memory size of XXXXXX bytes exhausted <...>
- PHP 中list()出现Undefined offset: 0错误
- SqlServer 优化技巧
- Nestedset 出现 Node must exists. 错误解决方案
- SpringBoot @NotBlank 不生效问题
点击排行
- Error in execution; nested exception is io.lettuce.core.RedisCommandExecutionException: ERR DISABLE You can't write or read against a disable instance
- Debian apt 使用国内镜像
- RocketMQ 出现 sendDefaultImpl call timeout 问题
- 类 BASE64Decoder 程序包 sun.misc 找不到符号
- SpringBoot @NotBlank 不生效问题
- 记一次 Mybatis-Plus 自动填充无效问题解决
- SpringBoot 2.x 文件上传出现 The field file exceeds its maximum permitted size of 1048576 bytes
- nuxt 项目完整部署方案
站长推荐
猜你喜欢
- npm 出现 Unexpected token < in JSON at position 21330
- 【代码片段】MySQL新建表添加基础字段
- idea去掉Smart commands execution提示
- cmder vim方向键无法使用 解决方案
- CentOS 安装 Docker
- gulp3 在 node12 上运行出现异常 primordials is not defined
- Linux 查看磁盘、磁盘分区、挂载磁盘、卸载磁盘操作
- SpringBoot 集成 Elasticsearch 7.8.1 出现错误 Factory method 'elasticsearchRestHighLevelClient' threw exception; nested exception is java.lang.NoSuchFieldError: IGNORE_DEPRECATIONS
- Linux 安装 Tengine
- Zookeeper 找不到或无法加载主类 org.apache.zookeeper.server.quorum.QuorumPeerMain