【问题标题】:Static Resources (js,css..) in Spring MVC app not available when adding spring-data-rest添加spring-data-rest时Spring MVC应用程序中的静态资源(js,css ..)不可用
【发布时间】:2013-06-06 12:39:03
【问题描述】:

我有一个运行良好的现有 mvc 应用程序,但是当我添加时

<bean class="org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration"></bean>

启用 spring-data-rest 然后是通过提供的静态资源

<mvc:resources mapping="/resources/**" location="/resources/" />

无法访问。 实际上,我在请求静态资源时会在日志中得到这个

2013-06-06 15:33:21,035 DEBUG DispatcherServlet.doService(823) - DispatcherServlet with name 'eips-databus' processing GET request for [/eips-databus/scripts/easyUI/themes/gray/easyui_custom.css]
2013-06-06 15:33:21,035 DEBUG RequestMappingHandlerMapping.getHandlerInternal(226) - Looking up handler method for path /scripts/easyUI/themes/gray/easyui_custom.css
2013-06-06 15:33:21,035 DEBUG ExceptionHandlerExceptionResolver.resolveException(132) - Resolving exception from handler [null]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation

有什么建议吗? 提前致谢

【问题讨论】:

    标签: spring spring-data spring-data-rest


    【解决方案1】:

    我面临着相同的一些差异。就我而言,我为静态资源添加了处理程序:

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("/WEB-INF/static/");
    }
    

    之后,一些具有长路径的静态文件(如/a/b/c/d.css/a/b/c/d.js)用作静态内容,但有些文件(如/a/b/c.js)则不是。

    我发现在我的例子中 RepositoryRestHandlerMapping 使用 Ordered.HIGHEST_PRECEDENCE 注册自己,并且大多数 CSS 和 JavaScript 请求都通过像 [/{repository}/{id}/{property}] 这样的规则处理到这个处理程序中。

    This is a bug in Spring-Data,现在已修复(感谢 Oliver Gierke),您可以从 snapshot repo 获得修复版本 2.0.0.BUILD-SNAPSHOT,我希望这可以帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-09
      • 2015-04-12
      • 2019-01-31
      • 2014-10-15
      • 2023-04-01
      相关资源
      最近更新 更多