包中的spring字段passwordencoder需要类型为“org.springframework.security.crypto.password.passwordencoder”的bean,但找不到该bean

ogsagwnx  于 2021-07-23  发布在  Java
关注(0)|答案(1)|浏览(460)

我正在尝试使用配置文件自动连接服务类中的密码编码器:

@Configuration
@EnableWebSecurity
class SecurityConfiguration : WebSecurityConfigurerAdapter() {

@Bean
fun passwordEncoder(): PasswordEncoder {
    return BCryptPasswordEncoder()
}

intellij将@autowired var passwordencoder检测为autowired的候选。

@Service
class userServiceImpl : UserService {

@Autowired
private lateinit var passwordEncoder : PasswordEncoder

我知道调用配置是因为调用了配置文件的其他元素。


***************************

APPLICATION FAILED TO START

***************************

Description:
Field passwordEncoder in com.example.project.service.userServiceImpl required a bean of type 'org.springframework.security.crypto.password.PasswordEncoder' that could not be found.
 The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'org.springframework.security.crypto.password.PasswordEncoder' in your configuration.
g52tjvyc

g52tjvyc1#

我在我的主类中为有问题的包添加了一个组件扫描注解,这样就消除了错误

@SpringBootApplication
    @ComponentScan("com.example.project.config")
    class myApplication

相关问题