A
A
aramtop2021-12-28 14:07:27
Java
aramtop, 2021-12-28 14:07:27

Why, after adding the Interceptor, did I get Cannot invoke "(int)" because "this.userRepository" is null?

After I implemented the Interceptor preHandle, from whose handler this class is called, I started getting an error: Cannot invoke "com.____________.highfive_api.UserRepository.findByVKid(int)" because "this.userRepository" is null

@Component
public class Auth {
    @Autowired
    UserRepository userRepository;

    private static final String ENCODING = "UTF-8";
    java.util.logging.Logger logger =  java.util.logging.Logger.getLogger(this.getClass().getName());

    public Map<String, Integer> check(String app_url) throws java.lang.Exception {
        Users user = new Users();
        ValidateVK validationOnVK = new ValidateVK();
        int[] result = (int[]) validationOnVK.check(app_url);

        HashMap<String, Integer> map = new HashMap<>();

        if(result[0] == 1){
            if(userRepository.findByVKid(result[1]) == null){
                user.setStatus("1");
                user.setVKid(result[1]);
                userRepository.save(user);
            }
            map.put("status", 1);
            map.put("userid", result[1]);
        }else{
            //everything is bad
            map.put("status", 0);
        }
        return map;
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question