无法解析org.springframework.security.authentication.AuthenticationManager类型.它是从所需的.class文件间接引用的

mch*_*nta 5 spring spring-security

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth.inMemoryAuthentication().withUser("abcde").password("123456").roles("USER");   
}
Run Code Online (Sandbox Code Playgroud)

而且我在最后一行收到错误,它说

The type org.springframework.security.authentication.AuthenticationManager cannot be resolved. It is indirectly referenced from required .class files
Run Code Online (Sandbox Code Playgroud)

我找了一个解决方案,找不到解决方法.

Sar*_*dra 6

将spring-security-core添加到构建路径中.如果您已有,请下载最新版本.

 <dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-core</artifactId>
    <version>5.0.0.RELEASE</version>
 </dependency>
Run Code Online (Sandbox Code Playgroud)

mvn clean install之后,如果你仍然在eclipse中看到错误.刷新项目.这对我有用.


Rad*_*nta 5

将 spring-security-core.jar 添加到项目的 Build Path 中。如果您使用的是 Eclipse,请右键单击项目 --> 属性 --> Java 构建路径 --> 库 --> 单击添加 jar 或添加外部 jar 并指向 jar 文件。

另外,做干净的构建。