I built a Spring Boot application and added several methods in the service layer. Then I autowired their class into the Controller. IDEA shows an error that
Non-static method 'findAll()' cannot be referenced from a static context.
@Autowired
public UserMapper Usermanager;
public List<UserEntity> findAll() {
List<UserEntity> list = Usermanager.findALL();
return list;
}
public List<UserEntity> findByName() {
List<UserEntity> list = Usermanager.findByName();
return list;
}
Static value is belong to the class instead of the object. For this reason if we use a static value NPE(NonePointerException) will happen.