@Autowired does not work with my service

1

I always run the method that accesses what is in another class with @Autowired it becomes null, follow the code below:

@Component
public class TokenAuthenticationService {

    @Autowired
    UserRoleServiceSecurity service;
    ...
    void addAuthentication(HttpServletResponse response, String username) throws IOException {
        UserRole us = service.buscarPorUsername(username); //Aqui fica nulo e solta um java.lang.NullPointerException: null
        System.out.println(us.getRole());

The UserRoleServiceSecurity.java class:

@Service
public class UserRoleServiceSecurity {

    @Autowired
    UsuarioRepository repository;

    @Autowired
    UsuarioRoleRepository usRepository;

    public UserRole buscarPorUsername(String username) {
        return usRepository.buscarUserUsername(username);
    }
} 
    
asked by anonymous 26.01.2018 / 21:55

1 answer

0

I recommend watching @componantScan, put the path of your packages as the basePackage attribute. Also, I recommend annotating this class of service with the annotation @Service

    
02.02.2018 / 21:54