-8

I am trying to create a simple service file in spring, I am completely beginner in Java and therefore do not understand why I am getting an error message while on a given example it works fine.

Here's an error message:

Error:(24, 35) java: non-static method save(S) cannot be referenced from a static context

@Service
public class UserService {

    @Autowired
    protected static UserEntryRepository userEntryRepository;

    public static List<UserEntry> findAll() {
        return userEntryRepository.findAll();
    }

    public static UserEntry save(UserEntry entry) {
        return UserEntryRepository.save(entry);
    }
}

It seems there is a problem with .save but I do not understand why, if any more code is required please let me know ;)

Przemek Wojtas
  • 1,311
  • 5
  • 26
  • 51

1 Answers1

3

remove static from the autowired field and replace UserEntryRepository.save(entry); with userEntryRepository.save(entry);

Jobin
  • 5,610
  • 5
  • 38
  • 53
  • 1
    works fine such a stupid mistake – Przemek Wojtas Dec 21 '16 at 11:53
  • It took me 5 minutes to notice the change in `UserEntryRepository.save(entry);` and `userEntryRepository.save(entry);` just in in case you face it too its the upper case and lower case of class '**U**serEntryRepository' – Arpita Jul 12 '21 at 14:53