So I had no problems with my app until I decided that it's better to have a Service class to do all the logic stuff. And when i copy the exact same code that i initially had, i get NullPointer error.
This is what i had and it worked all well:
User user = userRepository.findById(id).get();
This is what i have in Service class:
public User findUserById(Integer id)
{
User user = userRepository.findById(id).get();
return user;
}
And this is what i call:
private UserService userService = new UserService();
User user = userService.findUserById(id);