1

Within a normal Spring Application, I have:

@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {
    @Override
    protected Map<String, MediaType> getDefaultMediaTypes() {
        Map<String, MediaType> mediaTypes = super.getDefaultMediaTypes();
        mediaTypes.put("extension", new MediaType("foo", "bar"));
        return mediaTypes;
    }
}

So I can do something like:

@RequestMapping(produces = "foo/bar")
public void test() { ... }

And then call:

http://.../myResource.extension

When I do this with Spring Boot, then extends WebMvcConfigurationSupport would prevent all the auto configuration.

So how can I easily register new Extension-Accept-Header mappings with Spring Boot?

Benjamin M
  • 23,599
  • 32
  • 121
  • 201

2 Answers2

2

This should do it, I have verified the code with Boot 1.2.1.RELEASE

@Configuration
 public class EnableWebMvcConfiguration extends WebMvcAutoConfiguration.EnableWebMvcConfiguration {

    @Override
    protected Map<String, MediaType> getDefaultMediaTypes() {
        Map<String, MediaType> mediaTypes = super.getDefaultMediaTypes();
        mediaTypes.put("extension", new MediaType("foo", "bar"));
        return mediaTypes;
    }
}
avi
  • 111
  • 1
  • 3
  • Spring Boot config seems to be really endlessly! `:D`. I looked at `WebMvcAutoConfiguration`, but didn't figure out that it injects its own `EnableWebMvcConfiguration`. I will try it in a few minutes! – Benjamin M Feb 13 '15 at 14:45
1

according to avi's answer, we should use extends WebMvcAutoConfiguration.EnableWebMvcConfiguration

For adding additional extensions and media types, it might be more easy to just override configureContentNegotiation:

@Override
protected void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
    configurer
        .mediaType("extension", new MediaType("foo", "bar"));
}
Benjamin M
  • 23,599
  • 32
  • 121
  • 201