SecurityContextHolder 导入在 Spring Boot 应用程序中不起作用

shu*_*pta 1 spring-security vaadin spring-boot

我在我的项目中添加了以下依赖项。

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-web</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-config</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)

尝试导入以下

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder
Run Code Online (Sandbox Code Playgroud)

其他文件,如 import org.springframework.security.authentication.AnonymousAuthenticationToken 正在导入但无法导入上述类。

我已经检查了这些类可用的 jar,但是 eclipse 在导入时没有显示它们;

Muk*_*med 5

将 spring 安全依赖替换为 Spring-Boot starter maven 依赖

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>          
    </dependency> 
Run Code Online (Sandbox Code Playgroud)