【发布时间】:2021-01-17 00:54:41
【问题描述】:
我无法在我的 SecurityConfig 类中自动装配 AuthenticationProvider Spring 框架实例。这很奇怪,因为我已经包含了必要的导入,并且 UserDetailsService(另一个 Spring Framework 类)可以自动装配而没有任何问题。这是我的代码:
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.security.authentication.AuthenticationProvider
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
import org.springframework.security.core.userdetails.UserDetailsService
import org.springframework.security.web.authentication.RememberMeServices
import org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices
@Configuration
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)
class SecurityConfig : WebSecurityConfigurerAdapter() {
companion object {
private const val REMEMBER_ME_KEY = "basdrwerdadev$#@safasfewrahl"
}
@Autowired private lateinit var authenticationProvider: AuthenticationProvider
@Autowired private lateinit var userDetailsService: UserDetailsService
...
也许我缺少依赖项?我添加了 Spring 安全依赖项
【问题讨论】:
标签: java spring spring-boot kotlin spring-security