WebSecurityConfigurerAdapter找不到这个类
时间: 2023-10-26 19:01:15 浏览: 63
WebSecurityConfigurerAdapter类找不到的原因是因为将入口类放置在了一个默认包中,而没有在pom.xml文件中引入Spring Security相关的包或Starter导致找不到对应的类。解决这个问题的方式是将启动类放入一个包中。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [SpringCloud 问题记录](https://blog.csdn.net/qq_31802135/article/details/89879344)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
相关问题
WebSecurityConfigurerAdapter 我找不到这个类
如果您正在使用Spring Security 5.x,WebSecurityConfigurerAdapter已经被弃用了。取而代之的是,您应该使用WebSecurityConfigurer接口并实现它的方法来配置您的安全性。如果您仍然希望使用WebSecurityConfigurerAdapter,您需要添加以下依赖项:
```xml
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>5.x.x.RELEASE</version>
</dependency>
```
然后,您可以使用以下代码来扩展WebSecurityConfigurerAdapter:
```java
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
// override methods here
}
```
找不到WebSecurityConfigurerAdapter
如果你在使用 Spring Security 的过程中出现了找不到 WebSecurityConfigurerAdapter 的问题,可能是因为你没有正确引入 Spring Security 的依赖或者版本不匹配。
首先,你需要在项目的 pom.xml 文件中添加 Spring Security 的依赖,例如:
```xml
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>5.5.0</version>
</dependency>
```
然后,你需要创建一个类继承自 WebSecurityConfigurerAdapter,并在该类中实现 configure 方法,例如:
```java
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/public/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.defaultSuccessUrl("/")
.permitAll()
.and()
.logout()
.logoutUrl("/logout")
.permitAll();
}
}
```
如果你仍然无法找到 WebSecurityConfigurerAdapter,你可以尝试清理项目并重新构建,或者检查一下你的 IDE 是否正确加载了项目的依赖。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)