Search in sources :

Example 1 with UrlBasedViewResolver

use of org.springframework.web.reactive.result.view.UrlBasedViewResolver in project spring-framework by spring-projects.

the class ViewResolverRegistry method freeMarker.

/**
	 * Register a {@code FreeMarkerViewResolver} with a ".ftl" suffix.
	 * <p><strong>Note</strong> that you must also configure FreeMarker by
	 * adding a {@link FreeMarkerConfigurer} bean.
	 */
public UrlBasedViewResolverRegistration freeMarker() {
    if (this.applicationContext != null && !hasBeanOfType(FreeMarkerConfigurer.class)) {
        throw new BeanInitializationException("In addition to a FreeMarker view resolver " + "there must also be a single FreeMarkerConfig bean in this web application context " + "(or its parent): FreeMarkerConfigurer is the usual implementation. " + "This bean may be given any name.");
    }
    FreeMarkerRegistration registration = new FreeMarkerRegistration();
    UrlBasedViewResolver resolver = registration.getViewResolver();
    resolver.setApplicationContext(this.applicationContext);
    this.viewResolvers.add(resolver);
    return registration;
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) UrlBasedViewResolver(org.springframework.web.reactive.result.view.UrlBasedViewResolver)

Example 2 with UrlBasedViewResolver

use of org.springframework.web.reactive.result.view.UrlBasedViewResolver in project spring-framework by spring-projects.

the class ViewResolverRegistryTests method customViewResolver.

@Test
public void customViewResolver() {
    UrlBasedViewResolver viewResolver = new UrlBasedViewResolver();
    this.registry.viewResolver(viewResolver);
    assertSame(viewResolver, this.registry.getViewResolvers().get(0));
    assertEquals(1, this.registry.getViewResolvers().size());
}
Also used : UrlBasedViewResolver(org.springframework.web.reactive.result.view.UrlBasedViewResolver) Test(org.junit.Test)

Aggregations

UrlBasedViewResolver (org.springframework.web.reactive.result.view.UrlBasedViewResolver)2 Test (org.junit.Test)1 BeanInitializationException (org.springframework.beans.factory.BeanInitializationException)1