Logger logger = LoggerFactory.getLogger(CustomWebSecurityExpressionRoot.class);
@Autowired
private IUserService userService;
public CustomWebSecurityExpressionRoot(Authentication a, FilterInvocation fi) {
super(a, fi);
}
public boolean isOwner(Integer id) {
String username = ((UserDetails) getPrincipal()).getUsername();
User user = new User();
if (userService == null) {
logger.debug("USER SERVICE NULL");
}
try {
user = userService.findByUsername(username);
} catch (NullPointerException e) {
e.printStackTrace();
logger.debug("NULL");
}
return id == user.getId();
}
Exception:
java.lang.NullPointerException
at waterfall.model.User.getId(User.java:62)
at waterfall.config.CustomWebSecurityExpressionRoot.isOwner(CustomWebSecurityExpressionRoot.java:37)
In other classes, like controller, it works perfectly fine but in the class above userService is null. I have no clue why it is null. What can cause my issue?