我正在尝试使用配置文件在我的服务类中自动装配密码编码器:
@Configuration
@EnableWebSecurity
class SecurityConfiguration : WebSecurityConfigurerAdapter() {
@Bean
fun passwordEncoder(): PasswordEncoder {
return BCryptPasswordEncoder()
}
Intellij 将 @Autowired var passwordEncoder 检测为自动装配的候选对象。
@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.
答案 0 :(得分:-1)
我在我的主类上为有问题的包添加了一个组件扫描注释,并消除了错误
@SpringBootApplication
@ComponentScan("com.example.project.config")
class myApplication