Java Code Examples for org.springframework.web.servlet.view.ViewResolverComposite

Following code examples demonstrate how to use org.springframework.web.servlet.view.ViewResolverCompositefrom spring-framework. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.springframework.web.servlet.view.ViewResolverCompositeand various code implementation of this class.

    public ViewResolver setupViewResolver() {
        ViewResolverComposite composite = new ViewResolverComposite();
        composite.setViewResolvers(Arrays.asList(
                new FreeMarkerViewResolver("/", ".ftl"),
                thymeleafViewResolver(),
                jspResolver()
        ));
        return composite;
    } 


    public void afterPropertiesSet() throws Exception {
        List<ViewResolver> viewResolvers = new ArrayList<>();
        viewResolvers.add(handlebars());
        
        ViewResolverComposite composite =
                applicationContext.getBean(VIEW_RESOLVER_BEAN_NAME, ViewResolverComposite.class);
        viewResolvers.addAll(composite.getViewResolvers());
        composite.setViewResolvers(viewResolvers);
    } 

	public void getMvcComponents(){
		
		Heart heart = Heart.getInstance();
		heart.setFrontendApplicationContext(webApplicationContext);
		
		ServletContext servletContext = webApplicationContext.getServletContext();
		Life life = Life.getInstance(servletContext);
		
		Map<String, HandlerMapping> handlerMappings = life.getHandlerMappings();
		assertEquals(5,handlerMappings.size());
		assertTrue(handlerMappings.get("beanNameHandlerMapping") instanceof BeanNameUrlHandlerMapping);
		assertTrue(handlerMappings.get("resourceHandlerMapping") instanceof SimpleUrlHandlerMapping);
		assertTrue(handlerMappings.get("defaultServletHandlerMapping") instanceof SimpleUrlHandlerMapping);
		assertTrue(handlerMappings.get("viewControllerHandlerMapping") instanceof SimpleUrlHandlerMapping);
		assertTrue(handlerMappings.get("requestMappingHandlerMapping") instanceof RequestMappingHandlerMapping);
		
		Map<String, HandlerAdapter> handlerAdapters = life.getHandlerAdapters();
		assertEquals(3,handlerAdapters.size());
		assertTrue(handlerAdapters.get("simpleControllerHandlerAdapter") instanceof SimpleControllerHandlerAdapter);
		assertTrue(handlerAdapters.get("requestMappingHandlerAdapter") instanceof RequestMappingHandlerAdapter);
		assertTrue(handlerAdapters.get("httpRequestHandlerAdapter") instanceof HttpRequestHandlerAdapter);
		
		Map<String, ViewResolver> viewResolvers = life.getViewResolvers();
		assertEquals(2,viewResolvers.size());
		assertTrue(viewResolvers.get("mvcViewResolver") instanceof ViewResolverComposite);
		assertTrue(viewResolvers.get("getViewResolver") instanceof InternalResourceViewResolver);
		
		Map<String, HandlerExceptionResolver> handlerExceptionResolvers = life.getHandlerExceptionResolvers();
		assertEquals(1,handlerExceptionResolvers.size());
		assertTrue(handlerExceptionResolvers.get("handlerExceptionResolver") instanceof HandlerExceptionResolverComposite);
		
		Map<String, LocaleResolver> localeResolvers = life.getLocaleResolvers();
		assertEquals(0,localeResolvers.size());
		
		Map<String, ThemeResolver> themeResolvers = life.getThemeResolvers();
		assertEquals(0,themeResolvers.size());
		
		Map<String, RequestToViewNameTranslator> requestToViewNameTranslators = life.getRequestToViewNameTranslators();
		assertEquals(0,requestToViewNameTranslators.size());
		
		Map<String, FlashMapManager> flashManagers = life.getFlashMapManagers();
		assertEquals(0,flashManagers.size());
		
	} 

Advertisement
Javadoc
A org.springframework.web.servlet.ViewResolver that delegates to others. @author Sebastien Deleuze @

author Rossen Stoyanchev @since 4.1

Read More
Advertisement