如何解决,与豆子缺乏可见性有关的问题?



我正在编写一个api,我想检查注册的性能,而应用程序不想启动,因为它没有看到Bean ->PasswordEncoder .

你知道我该怎么做才能让它工作吗?

:

com.example.socialplatform.service.AuthorizationService中构造函数的参数0需要一个类型为'org.springframework.security.crypto.password '的bean。无法找到的密码编码器。考虑定义一个类型为"org.springframework.security.crypto.password"的bean。PasswordEncoder'在您的配置。'

我类:

SecuritySettings

@EnableWebSecurity
public class SecuritySettings extends WebSecurityConfigurerAdapter {   
/* base class security, provides all the default security configuration  
which i can override and customize */
@Override
public void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity.csrf().disable()                                   
.authorizeRequests()
.antMatchers("/api/authorization/**")
.permitAll()
.anyRequest()
.authenticated();
}

@Bean
public PasswordEncoder encoder() {
return new BCryptPasswordEncoder();
}
}

我试着重建项目,和maven.

如果这是一个Spring Boot项目,解决这个问题的一个简单方法是将这个类与主类放在同一个包中。它能工作是因为@SpringBootApplication暗示了@Configuration和@ComponentScan注解。

如果这不是一个SpringBoot项目,则必须将bean放在配置类中。这是一个带@Configuration注释的类。

最新更新