use of org.springframework.web.servlet.view.ContentNegotiatingViewResolver in project spring-framework by spring-projects.
the class ViewResolverRegistryTests method contentNegotiationAddsDefaultViewRegistrations.
@Test
public void contentNegotiationAddsDefaultViewRegistrations() {
MappingJackson2JsonView view1 = new MappingJackson2JsonView();
this.registry.enableContentNegotiation(view1);
ContentNegotiatingViewResolver resolver1 = checkAndGetResolver(ContentNegotiatingViewResolver.class);
assertEquals(Arrays.asList(view1), resolver1.getDefaultViews());
MarshallingView view2 = new MarshallingView();
this.registry.enableContentNegotiation(view2);
ContentNegotiatingViewResolver resolver2 = checkAndGetResolver(ContentNegotiatingViewResolver.class);
assertEquals(Arrays.asList(view1, view2), resolver2.getDefaultViews());
assertSame(resolver1, resolver2);
}
use of org.springframework.web.servlet.view.ContentNegotiatingViewResolver in project spring-security-oauth by spring-projects.
the class WebMvcConfig method contentViewResolver.
@Bean
public ContentNegotiatingViewResolver contentViewResolver() throws Exception {
ContentNegotiatingViewResolver contentViewResolver = new ContentNegotiatingViewResolver();
ContentNegotiationManagerFactoryBean contentNegotiationManager = new ContentNegotiationManagerFactoryBean();
contentNegotiationManager.addMediaType("json", MediaType.APPLICATION_JSON);
contentViewResolver.setContentNegotiationManager(contentNegotiationManager.getObject());
contentViewResolver.setDefaultViews(Arrays.<View>asList(new MappingJackson2JsonView()));
return contentViewResolver;
}
use of org.springframework.web.servlet.view.ContentNegotiatingViewResolver in project spring-security-oauth by spring-projects.
the class WebMvcConfig method contentViewResolver.
@Bean
public ContentNegotiatingViewResolver contentViewResolver() throws Exception {
ContentNegotiationManagerFactoryBean contentNegotiationManager = new ContentNegotiationManagerFactoryBean();
contentNegotiationManager.addMediaType("json", MediaType.APPLICATION_JSON);
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/jsp/");
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;
}
Aggregations