0

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?

2
  • stackoverflow.com/questions/7197268/… Commented Apr 29, 2016 at 16:13
  • I don't seem to have any problems with returning JSON. It's only when I try to get image resources (png, jpg) Commented Apr 29, 2016 at 16:21

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.