How can I call a default interface method from an implementation class?
@Repository
public class FileInfoRepoImpl implements FileInfoRepo {
@Autowired
MongoTemplate mongoTemplate;
public UpdateResult updateFileInfo(FileInfo fileInfo) {
Query query = new Query(Criteria.where("id").is(fileInfo.getId()));
Update update = new Update();
update.set("name", fileInfo.getName());
update.set("size", fileInfo.getSize());
update.set("contentType", fileInfo.getContentType());
UpdateResult result = mongoTemplate.updateFirst(query, update, FileInfo.class);
return result;
}
@Override
public <S extends FileInfo> S save(S entity) {
//return FileInfoRepo.super.save(entity); # not compilled
throw new UnsupportedOperationException("Unimplemented method 'findAllById'");
}
The FileInfoRepo interface looks like this:
public interface FileInfoRepo extends MongoRepository<FileInfo, String> {
List<FileInfo> findByName(String name);
UpdateResult updateFileInfo(FileInfo fileInfo);
}
Please help find solution. Thank you for every suggestion.
Interfaces, by definition, do not actually have method implementations, so there is no "default" method here. You can understand more about java interfaces here
Part 2 of your issue here is that you may not need to implement some of those methods that your are writing. In spring boot, extending the MongoRepository class gives you the simple stuff for free. Like save, and findById.
Go through this module, it'll help with understanding
Here's the part about the MongoRepository specifically
Hope that helps, welcome to Spring Boot!