【问题标题】:How do I enable matrix variable support without clobbering Spring Boot configuration?如何在不破坏 Spring Boot 配置的情况下启用矩阵变量支持?
【发布时间】:2014-07-01 19:57:45
【问题描述】:

我想同时使用 Spring Boot 来利用 JacksonAutoConfiguration 并为我的控制器启用矩阵变量,这需要调用 RequestMappingHandlerMapping.setRemoveSemicolonContent(false)

当这个 trivial Gist 在没有扫描到 WebMvcConfiguration 的情况下运行时,输出是

{"dateTime":1404244199372}

当它被扫描进来时,输出是

{"dateTime":{"year":2014,"era":1,"dayOfYear":182,"dayOfWeek":2,"dayOfMonth":1,"centuryOfEra":20,"yearOfEra":2014,"yearOfCentury":14,"weekyear":2014,"monthOfYear":7,"weekOfWeekyear":27,"secondOfDay":76856,"minuteOfDay":1280,"hourOfDay":21,"minuteOfHour":20,"secondOfMinute":56,"millisOfSecond":807,"millisOfDay":76856807,"chronology":{"zone":{"fixed":false,"uncachedZone":{"cachable":true,"fixed":false,"id":"Europe/Berlin"},"id":"Europe/Berlin"}},"zone":{"fixed":false,"uncachedZone":{"cachable":true,"fixed":false,"id":"Europe/Berlin"},"id":"Europe/Berlin"},"millis":1404242456807,"afterNow":false,"beforeNow":true,"equalNow":false}}  

很难说为什么会发生这种情况,在ObjectMappers、JodaModuleMappingJackson2HttpMessageConverter 中挖掘之后我仍然不确定。

知道如何配置 Spring 以利用 Spring Boot 并能够支持矩阵变量吗?

更新:在DelegatingWebMvcConfiguration 中扫描导致的其他损坏包括Boot 的http.mappers.jsonPrettyPrint 支持。

【问题讨论】:

    标签: spring-mvc spring-boot


    【解决方案1】:

    here 所述,以下内容适用于 Spring Boot 1.2。

    @Configuration
    public class WebMvcConfig extends WebMvcConfigurerAdapter {
    
        @Override
        public void configurePathMatch(PathMatchConfigurer configurer) {
    
            UrlPathHelper urlPathHelper = new UrlPathHelper();
            urlPathHelper.setRemoveSemicolonContent(false);
    
            configurer.setUrlPathHelper(urlPathHelper);
        }
    }
    

    【讨论】:

      【解决方案2】:

      我认为您可能只需要从引导自动配置中复制所需的位。或者向 Spring Framework 提出问题以获得对添加到 WebMvcConfigurer 的分号功能的支持。另一件可能可行的事情是直接添加RequestMappingHandlerMapping(而不是为您的配置使用基类)。

      【讨论】:

        猜你喜欢
        • 2011-02-05
        • 1970-01-01
        • 1970-01-01
        • 2019-06-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-31
        • 2019-10-22
        相关资源
        最近更新 更多