【发布时间】:2016-02-23 15:01:32
【问题描述】:
在 Spring Boot 应用程序中,我收到此错误
创建名为“webSecurityConfigurerAdapter”的 bean 时出错: 注入自动装配的依赖项失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:
无法自动装配字段:私有 server.service.UserServiceImpl server.ServerApplicationSecurity.userDetailsService;嵌套异常 是org.springframework.beans.factory.NoSuchBeanDefinitionException:
找不到 [server.service.UserServiceImpl] 类型的合格 bean 依赖项:预计至少有 1 个符合自动装配条件的 bean 这种依赖的候选人。依赖注解: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class ServerApplicationSecurity extends WebSecurityConfigurerAdapter {
@Autowired
private UserServiceImpl userDetailsService;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService);
}
...
}
@Service
public class UserServiceImpl implements UserDetailsService, UserService {
private final UserAppRepository repository;
@Autowired
public UserServiceImpl(final UserAppRepository repository) {
this.repository = repository;
}
...
}
我的班级使用@Service 并且 bean 已自动装配,所以我不明白为什么会出现此错误。
【问题讨论】:
标签: spring spring-boot spring-4