Reputation: 117
I'm trying very simple scenario:
I generated a Spring Boot (v1.3.3) project using start.spring.io initialiser having selected Web dependency. I have then put sample JS, CSS and PNG files into resources/static
folder and started up the webapp.
Now when I try to access JS and CSS resources everything's fine, but for the image it throws org.springframework.web.HttpMediaTypeNotAcceptableException
(Could not find acceptable representation) and returns error 406.
Is there any configuration to be done to serve static images from resources/static folder?
Upvotes: 0
Views: 3330
Reputation: 179
No further configuration should be required. (I'm also serving images from the static folder of a Spring Boot v1.3.3 app.)
How are you accessing the images? Are you calling servletContext.getResourceAsStream("filename") from a Controller and returning a byte array? If that's the case you may need to add e.g. produces = MediaType.IMAGE_JPEG_VALUE to your @RequestMapping annotation.
If using JSPs you should just be able to use the Spring url tag in the following manner:
<spring:url value="/path/to/your-image.jpg" var="logoImg"/>
<img src="${logoImg}">
..where the path starts from within the static folder.
Upvotes: 1