img not showing using Thymeleaf and Springboot

komal dedhia picture komal dedhia ยท Nov 19, 2014 ยท Viewed 20.4k times ยท Source

I am using thymeleaf along with springboot

I am not able to view any images in my HTML file. I have tried all different ways of doing the same in thymeleaf but no luck.

Here is my project folder structure

๐Ÿ— src
โ””โ”€โ”€โ”€ ๐Ÿ— main
    โ””โ”€โ”€โ”€ ๐Ÿ— resources
        โ”œโ”€โ”€โ”€ ๐Ÿ— templates
        โ”œโ”€โ”€โ”€ ๐Ÿ— css
        โ””โ”€โ”€โ”€ ๐Ÿ— images

HTML File

<head>
    <title>Community Bike Share Web Application</title>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0"/>
    <link rel="stylesheet" th:href="@{/webjars/bootstrap/3.1.1/css/bootstrap.min.css}" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
</head>

<div>
    <img th:src="@{/images/taiwan_Bicycle_Ride_hd_wallpaper_8.jpg}"
         src="../images/taiwan_Bicycle_Ride_hd_wallpaper_8.jpg" class="img-responsive" alt="Responsive image"/>
</div>

Answer

Andy Wilkinson picture Andy Wilkinson ยท Nov 19, 2014

With Boot's default configuration, your images (and other static content), need to be beneath src/main/resources/static. For example, to serve content from /images put the files in src/main/resources/static/images