Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't load image with spring boot thymeleaf

I'm very new to spring boot and following Guru spring framework tutorial.

My simple spring boot application runs successfully and my controller works fine. I have used thymeleaf to show html pages and used some bootstrap css.everything works fine but an image tag that I have in one of my html pages. Thymeleaf shows the correct page when I run the app but image is not shown.I googled about this and put my images under /resources/static/images.This is my project structure :

enter image description here

I have also copied the same image to templates directory and used both files but none can be loaded.

This is my html file :

enter image description here

And this is what I get when I run the application :

enter image description here

404 not found error :

enter image description here

Can anyone tell me what I'm missing?

like image 360
Navid Avatar asked Nov 28 '22 06:11

Navid


1 Answers

Try changing to

<img src="../static/images/pirate.jpg" width="1000" th:src="@{images/pirate.jpg}"/>
like image 164
Alien Avatar answered Dec 04 '22 08:12

Alien