Spring-boot, thymeleaf load uploaded image without application server restart

2.4k views Asked by At

My question is, what is the best practice to store images with spring boot and thymeleaf, if I want to load the image without the restart of the application. At the moment I'm able to upload the image so I see it in the uploaded folder and in the database I've stored It's name, But then when I refresh the page the Image is not loaded. I'm retrieving the image standard way in thymeleaf <img th:src="@{'../images/'+${product.image}}". The path is correct because after restart of the server the image is loaded.I guess there is a problem with static folder that It's included in jar and couldn't be changed. But what is the best practice to solve this kind of problem in spring boot. Thanks

1

There are 1 answers

0
ndrone On BEST ANSWER

The problem is the static directory is loaded at startup. So any changes files added after the ApplicationContext is finished. You probably would be interested in this post: Refreshing static content with Spring MVC and Boot I would look past Dave Syer's post as he is talking about the IDE only, but the answer below that by Steve should help you.