Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpringMVC: Adding a mediatype to static resources to be served

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!

like image 780
myborobudur Avatar asked Jun 03 '11 08:06

myborobudur


People also ask

Which bean serve static resources in spring?

Spring Boot comes with a pre-configured implementation of ResourceHttpRequestHandler to facilitate serving static resources. By default, this handler serves static content from any of the /static, /public, /resources, and /META-INF/resources directories that are on the classpath.

How do I access static resources?

From Setup, enter Static Resources in the Quick Find box, then select Static Resources. To view the resource details, click the name of a resource. Available details include the MIME type, the size of the resource in bytes, when it was created, and when it was last modified.

Where do static files go in spring boot?

The file is located in the src/main/resources/static directory, which is a default directory where Spring looks for static content. In the link tag we refer to the main. css static resource, which is located in the src/main/resources/static/css directory. In the main.


1 Answers

Add this on your web.xml

<mime-mapping>
   <extension>json</extension>
    <mime-type>application/json</mime-type>
</mime-mapping>
like image 135
gouki Avatar answered Oct 17 '22 23:10

gouki