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 :
- Spring boot
NB: The creation of spring using spring boot and Maven is explained here http://mkaroune.e-monsite.com/pages/spring-boot-hiberante-project/project-creation.html. 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-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