Get images from external folder on disk.

A quick guide to display images from external folder on disk. An image (dance.png) exists in the directory

System.getProperty("user.home") + "\\images"

The application is executed on windows.

Technologies used in this article :

  1. Spring boot
  2. Maven
  3. Intellij

NB: The creation of spring using spring boot and Maven is explained here You do not need to add all the dependencies as shown in the article. Only DevTools, Web and Thymeleaf are needed in this example

Bellow is the project structure.


1. DisplayApplication is an auto-generated class. Run this class to start the application.

2. DisplayImage controller.

3. Add the new location of the folder images by customizing the default configuration using the interface WebMvcConfigurer

Defines callback methods to customize the Java-based configuration for Spring MVC enabled via @EnableWebMvc.

@EnableWebMvc-annotated configuration classes may implement this interface to be called back and given a chance to customize the default configuration.

4. Thymeleaf added in src/main/resources/templates/

5. pom.xml file

6. Demo: Access http://localhost:8080


Comments (1)

  • 1. Rafael | 09/05/2019
Thank you, your clear explanation made me save loads of time!

Add a comment