SpringMVC: Adding a mediatype to static resources to be served
Asked Answered
W

1

6

in my spring-mvc application I'm serving some static resources. JavaScrips, CSS and images get served correctly but there are also some json files which not get delivered.

So this file I can see in the browser: http://localhost:8080/path/to/resources/example.png

But this file (which is in the same directory) I don't receive: http://localhost:8080/path/to/resources/example.json

I'm getting this:

DEBUG: org.springframework.web.servlet.resource.ResourceHttpRequestHandler - No media type found for ServletContext resource [/resources/path/to/resources/example.json] - returning 404

So I would assume that I need to add somewhere this mediatype extension (.json) in the configuration but I can't find it.

Help please!

Wouldst answered 3/6, 2011 at 8:57 Comment(3)
Can you share the static resource configuration in your applications? The <mvc:resource ...> configurationsShamrock
<resources mapping="/**" location="/resources/" />Wouldst
Have you enabled <mvc:annotation-driven /> in your configuration.Shamrock
E
13

Add this on your web.xml

<mime-mapping>
   <extension>json</extension>
    <mime-type>application/json</mime-type>
</mime-mapping>
Euphorbia answered 3/6, 2011 at 10:5 Comment(1)
Thanks! Took awhile to find this answer, but it worked for me too. In my case, all I was getting was a 404.Tedmund

© 2022 - 2024 — McMap. All rights reserved.