We have wired up a repository to interface with MongoDB through Spring Data. Now we can start hooking it into our ImageService.
The first thing we need to do is inject our repository into the service, like this:
@Service public class ImageService { ... private final ResourceLoader resourceLoader; private final ImageRepository imageRepository; public ImageService(ResourceLoader resourceLoader, ImageRepository imageRepository) { this.resourceLoader = resourceLoader; this.imageRepository = imageRepository; } ... }
In the previous chapter, we loaded Spring's ResourceLoader. In this chapter, we are adding ImageRepository to our constructor.
Previously, we looked up the names of the existing uploaded files, and constructed a Flux of Image...