1
votes

In a spring boot application, i get this error

Error creating bean with name 'webSecurityConfigurerAdapter': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException:

Could not autowire field: private server.service.UserServiceImpl server.ServerApplicationSecurity.userDetailsService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:

No qualifying bean of type [server.service.UserServiceImpl] 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)}

@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;
    }
    ...
}

My class use @Service and the bean have Autowired, so i don't understand why i get this error.

1

1 Answers

1
votes

This:

@Autowired
private UserServiceImpl userDetailsService;

Should be this:

@Autowired
private UserDetailsService userDetailsService;

Reference your beans by interface, not by implementation. If you're still having an issue then your UserServiceImpl @Service is likely not being found by Spring.