Search in sources :

Example 6 with InternalResourceViewResolver

use of org.springframework.web.servlet.view.InternalResourceViewResolver in project spring-framework by spring-projects.

the class WebMvcConfigurationSupport method mvcViewResolver.

/**
	 * Register a {@link ViewResolverComposite} that contains a chain of view resolvers
	 * to use for view resolution.
	 * By default this resolver is ordered at 0 unless content negotiation view
	 * resolution is used in which case the order is raised to
	 * {@link org.springframework.core.Ordered#HIGHEST_PRECEDENCE
	 * Ordered.HIGHEST_PRECEDENCE}.
	 * <p>If no other resolvers are configured,
	 * {@link ViewResolverComposite#resolveViewName(String, Locale)} returns null in order
	 * to allow other potential {@link ViewResolver} beans to resolve views.
	 * @since 4.1
	 */
@Bean
public ViewResolver mvcViewResolver() {
    ViewResolverRegistry registry = new ViewResolverRegistry();
    registry.setContentNegotiationManager(mvcContentNegotiationManager());
    registry.setApplicationContext(this.applicationContext);
    configureViewResolvers(registry);
    if (registry.getViewResolvers().isEmpty()) {
        String[] names = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.applicationContext, ViewResolver.class, true, false);
        if (names.length == 1) {
            registry.getViewResolvers().add(new InternalResourceViewResolver());
        }
    }
    ViewResolverComposite composite = new ViewResolverComposite();
    composite.setOrder(registry.getOrder());
    composite.setViewResolvers(registry.getViewResolvers());
    composite.setApplicationContext(this.applicationContext);
    composite.setServletContext(this.servletContext);
    return composite;
}
Also used : ViewResolverComposite(org.springframework.web.servlet.view.ViewResolverComposite) InternalResourceViewResolver(org.springframework.web.servlet.view.InternalResourceViewResolver) Bean(org.springframework.context.annotation.Bean)

Example 7 with InternalResourceViewResolver

use of org.springframework.web.servlet.view.InternalResourceViewResolver in project spring-framework by spring-projects.

the class ViewResolverRegistryTests method customViewResolver.

@Test
public void customViewResolver() {
    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver("/", ".jsp");
    this.registry.viewResolver(viewResolver);
    assertSame(viewResolver, this.registry.getViewResolvers().get(0));
}
Also used : InternalResourceViewResolver(org.springframework.web.servlet.view.InternalResourceViewResolver) Test(org.junit.Test)

Example 8 with InternalResourceViewResolver

use of org.springframework.web.servlet.view.InternalResourceViewResolver in project spring-framework by spring-projects.

the class ViewResolverRegistryTests method jsp.

@Test
public void jsp() {
    this.registry.jsp("/", ".jsp");
    InternalResourceViewResolver resolver = checkAndGetResolver(InternalResourceViewResolver.class);
    checkPropertyValues(resolver, "prefix", "/", "suffix", ".jsp");
}
Also used : InternalResourceViewResolver(org.springframework.web.servlet.view.InternalResourceViewResolver) Test(org.junit.Test)

Example 9 with InternalResourceViewResolver

use of org.springframework.web.servlet.view.InternalResourceViewResolver in project spring-framework by spring-projects.

the class ViewResolverRegistryTests method jspDefaultValues.

@Test
public void jspDefaultValues() {
    this.registry.jsp();
    InternalResourceViewResolver resolver = checkAndGetResolver(InternalResourceViewResolver.class);
    checkPropertyValues(resolver, "prefix", "/WEB-INF/", "suffix", ".jsp");
}
Also used : InternalResourceViewResolver(org.springframework.web.servlet.view.InternalResourceViewResolver) Test(org.junit.Test)

Example 10 with InternalResourceViewResolver

use of org.springframework.web.servlet.view.InternalResourceViewResolver in project spring-security-oauth by spring-projects.

the class WebMvcConfig method viewResolver.

@Bean
public ViewResolver viewResolver() {
    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
    viewResolver.setPrefix("/WEB-INF/jsp/");
    viewResolver.setSuffix(".jsp");
    return viewResolver;
}
Also used : InternalResourceViewResolver(org.springframework.web.servlet.view.InternalResourceViewResolver) ContentNegotiationManagerFactoryBean(org.springframework.web.accept.ContentNegotiationManagerFactoryBean) Bean(org.springframework.context.annotation.Bean) ConversionServiceFactoryBean(org.springframework.context.support.ConversionServiceFactoryBean)

Aggregations

InternalResourceViewResolver (org.springframework.web.servlet.view.InternalResourceViewResolver)15 Test (org.junit.Test)7 Bean (org.springframework.context.annotation.Bean)6 ContentNegotiationManagerFactoryBean (org.springframework.web.accept.ContentNegotiationManagerFactoryBean)2 ContentNegotiatingViewResolver (org.springframework.web.servlet.view.ContentNegotiatingViewResolver)2 MappingJackson2JsonView (org.springframework.web.servlet.view.json.MappingJackson2JsonView)2 ArrayList (java.util.ArrayList)1 ServletException (javax.servlet.ServletException)1 Before (org.junit.Before)1 ConversionServiceFactoryBean (org.springframework.context.support.ConversionServiceFactoryBean)1 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)1 MockServletContext (org.springframework.mock.web.test.MockServletContext)1 Jaxb2Marshaller (org.springframework.oxm.jaxb.Jaxb2Marshaller)1 MockMvc (org.springframework.test.web.servlet.MockMvc)1 ContentNegotiationManager (org.springframework.web.accept.ContentNegotiationManager)1 FixedContentNegotiationStrategy (org.springframework.web.accept.FixedContentNegotiationStrategy)1 HeaderContentNegotiationStrategy (org.springframework.web.accept.HeaderContentNegotiationStrategy)1 View (org.springframework.web.servlet.View)1 ViewResolverComposite (org.springframework.web.servlet.view.ViewResolverComposite)1