SpringMVC:将mediatype添加到要提供的静态资源

myb*_*dur 5 spring-mvc staticresource

在我的spring-mvc应用程序中,我正在提供一些静态资源.JavaScrips,CSS和图像得到正确的服务,但也有一些json文件无法提供.

所以我在浏览器中可以看到这个文件: http:// localhost:8080/path/to/resources/example.png

但是这个文件(在同一个目录中)我没有收到: http:// localhost:8080/path/to/resources/example.json

我明白了:

DEBUG: org.springframework.web.servlet.resource.ResourceHttpRequestHandler - No media type found for ServletContext resource [/resources/path/to/resources/example.json] - returning 404
Run Code Online (Sandbox Code Playgroud)

所以我假设我需要在配置中添加这个mediatype扩展(.json),但我找不到它.

请帮忙!

gou*_*uki 13

在web.xml上添加它

<mime-mapping>
   <extension>json</extension>
    <mime-type>application/json</mime-type>
</mime-mapping>
Run Code Online (Sandbox Code Playgroud)