spring - Spring Boot 安全性上的 NoSuchMethodError
问题描述
我正在关注本教程:https ://www.baeldung.com/spring-boot-security-autoconfiguration 添加简单身份验证。到我的 Spring Boot 项目。当我尝试运行我的应用程序时,我总是收到此错误:
工厂方法“springSecurityFilterChain”抛出异常;嵌套异常是 java.lang.NoSuchMethodError: org.springframework.util.Assert.isTrue(ZLjava/util/function/Supplier;)V
IDK 为什么我得到这个或者这与版本问题有关。你们对此有什么想法吗?
解决方案
您可以将您的问题与此答案联系起来
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
安全配置类
@Configuration
@EnableWebSecurity
public class Config extends WebSecurityConfigurerAdapter{
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("username")
.password("password")
.roles("ADMIN","USER");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and()
.csrf().disable()
.authorizeRequests()
.antMatchers("/greetings").hasRole("ADMIN")
.and()
.httpBasic()
.and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
}
一个简单的restController
@GetMapping("/greetings")
public String greetings(){
return "Hello World!";
}
这是使用内存身份验证的基本安全性。您可以将 pom.xml 和 configuration.class 关联起来,在大多数情况下 spring-boot 会默认解析版本。
推荐阅读
- java - 不知道如何使用 Hermit 从 Java 本体中获取对象属性
- r - R将数据框转换为术语文档矩阵
- php - 文件大小不同于 SQL Server 和 PHP var_dump
- dns - VirtualHost 在我的 vps (ovh) 上不起作用
- sql - 如何在视图中调用存储过程?
- javascript - 隐藏基于复选框的下拉选项
- vue.js - 路径的路由配置“组件”:/ 不能是字符串 id
- docker - 连接 FTP 容器适用于 docker-compose 而不是 docker run
- java - 将校正公式应用于 5D 图像的每个通道
- html - 传递这样的函数的好习惯?