Arjun
Arjun

Reputation: 1262

Spring boot doesn't serve some of the images from the src/main/resources/public directory

I'm trying to develop a small webapp, for learning purpose, with spring boot,thymeleaf and mysql.
I'm using Eclipse IDE

Users can upload images to the app, My Controller class store the images in the src/main/resources/public/images folder and it's URL in the db.

The problem is, Eventhough the images saved by the controller exists in the src/main/resources/public/images directory, They are not directly visible in the public directory from Eclipse, as a result when referred from the served webpages, those images do not show up.

Some of the images I manually copy pasted into the public/images folder within the Eclipse .(To do that actually I had to move images to another directory as it's not possible to copy from and paste into the same folder)
Those images are rendered in the served web pages..

The other images saved by the controller, even though they exists in the same directory ,they are not directly visible from Eclipse IDE and they are't rendered in the served pages.


This is Directory's view within the eclipse and all these images are rendered correctly in the served webpages

enter image description here



This is the same directorie's view from the file system, and it contains many images that are not directly visible from eclipse.

enter image description here

And when I include these images in the webpages , they are'nt rendered even though they reside in the exact same folder as other images..

How to get around this issue?

Upvotes: 0

Views: 1219

Answers (1)

Alien
Alien

Reputation: 15908

When you run a spring boot or normal spring project using IDE it will bundle everything inside a war and then it serves that bundle so without restarting the server or re-running the application Eclipse doesn't loads the images.

This has nothing to do with spring boot.It is because of the Eclipse IDE as you know if you paste one image inside the folder directory but images wont load without restarting the server or re-running the application.

My recommendation would be to store images on any directory other than your deployed folder directory and access them without any issues.

I have done this inside tomcat folder without any issue.

Upvotes: 1

Related Questions