Пример #1
0
  @Bean
  public ContentNegotiatingViewResolver contentViewResolver() throws Exception {
    ContentNegotiationManagerFactoryBean contentNegotiationManager =
        new ContentNegotiationManagerFactoryBean();
    contentNegotiationManager.addMediaType("json", MediaType.APPLICATION_JSON);

    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
    viewResolver.setPrefix("/WEB-INF/views/");
    viewResolver.setSuffix(".jsp");

    MappingJackson2JsonView defaultView = new MappingJackson2JsonView();
    defaultView.setExtractValueFromSingleKeyModel(true);

    ContentNegotiatingViewResolver contentViewResolver = new ContentNegotiatingViewResolver();
    contentViewResolver.setContentNegotiationManager(contentNegotiationManager.getObject());
    contentViewResolver.setViewResolvers(Arrays.<ViewResolver>asList(viewResolver));
    contentViewResolver.setDefaultViews(Arrays.<View>asList(defaultView));
    return contentViewResolver;
  }
Пример #2
0
  @Bean
  public ContentNegotiationManagerFactoryBean contentManager() {
    ContentNegotiationManagerFactoryBean cnmfb = new ContentNegotiationManagerFactoryBean();
    cnmfb.setFavorPathExtension(true);
    cnmfb.setIgnoreAcceptHeader(false);
    cnmfb.setDefaultContentType(MediaType.TEXT_HTML);
    cnmfb.setUseJaf(false);

    Properties props = new Properties();
    props.setProperty("html", "text/html");
    props.setProperty("json", "application/json");
    props.setProperty("xml", "application/xml");
    cnmfb.setMediaTypes(props);

    return cnmfb;
  }