嗨,我有一个Autowired UsrDetailsService的问题,我发现很多其他人有同样的问题,但没有其他解决方案适合我(我不知道为什么)我使用java配置(没有xml)
Error code
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'securityConfig':
Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException:
Could not autowire field: private com.mycompany.delivery.service.AccountServiceImpl com.mycompany.delivery.config.SecurityConfig.accUserDetailsService;
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type [com.mycompany.delivery.service.AccountServiceImpl] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=accUserDetailsService)}
Run Code Online (Sandbox Code Playgroud)
当我将这个类自动连接到Controller时,或者其它任何地方都可以正常工作,其他一切都是自动装配好的,只有WebSecurityConfigurerAdapter我不能.
我的安全配置:
Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
@Qualifier("accUserDetailsService")
private AccountServiceImpl accUserDetailsService;
public AccountServiceImpl getAccUserDetailsService() {
return accUserDetailsService;
}
public …Run Code Online (Sandbox Code Playgroud)