Creating a reactive file controller

With our reactive image service in place, we can start to work on the reactive file controller.

For starters, let's create a HomeController as shown here:

    @Controller 
    public class HomeController { 
 
      private static final String BASE_PATH = "/images"; 
      private static final String FILENAME = "{filename:.+}"; 
 
      private final ImageService imageService; 
 
      public HomeController(ImageService imageService) { 
        this.imageService = imageService; 
      } 

The preceding code can be described as follows:

  • @Controller: This indicates that it is a web controller, and will be registered by Spring Boot to handle web requests.
  • BASE_PATH: This is a static string used to define the base of many routes.
  • FILENAME: This is a pattern for filenames ...

Get Developing Java Applications with Spring and Spring Boot now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.