Search in sources :

Example 1 with FreeMarkerViewResolver

use of org.springframework.web.reactive.result.view.freemarker.FreeMarkerViewResolver in project spring-boot by spring-projects.

the class FreeMarkerReactiveWebConfiguration method freeMarkerViewResolver.

@Bean
@ConditionalOnMissingBean(name = "freeMarkerViewResolver")
@ConditionalOnProperty(name = "spring.freemarker.enabled", matchIfMissing = true)
FreeMarkerViewResolver freeMarkerViewResolver() {
    FreeMarkerViewResolver resolver = new FreeMarkerViewResolver();
    resolver.setPrefix(getProperties().getPrefix());
    resolver.setSuffix(getProperties().getSuffix());
    resolver.setRequestContextAttribute(getProperties().getRequestContextAttribute());
    resolver.setViewNames(getProperties().getViewNames());
    return resolver;
}
Also used : FreeMarkerViewResolver(org.springframework.web.reactive.result.view.freemarker.FreeMarkerViewResolver) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)

Example 2 with FreeMarkerViewResolver

use of org.springframework.web.reactive.result.view.freemarker.FreeMarkerViewResolver in project spring-boot by spring-projects.

the class FreeMarkerAutoConfigurationReactiveIntegrationTests method render.

private MockServerWebExchange render(ApplicationContext context, String viewName) {
    FreeMarkerViewResolver resolver = context.getBean(FreeMarkerViewResolver.class);
    Mono<View> view = resolver.resolveViewName(viewName, Locale.UK);
    MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path"));
    view.flatMap((v) -> v.render(null, MediaType.TEXT_HTML, exchange)).block(Duration.ofSeconds(30));
    return exchange;
}
Also used : AutoConfigurations(org.springframework.boot.autoconfigure.AutoConfigurations) FreeMarkerConfig(org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfig) MockServerHttpRequest(org.springframework.mock.http.server.reactive.MockServerHttpRequest) StringWriter(java.io.StringWriter) MediaType(org.springframework.http.MediaType) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Mono(reactor.core.publisher.Mono) ApplicationContext(org.springframework.context.ApplicationContext) Test(org.junit.jupiter.api.Test) ReactiveWebApplicationContextRunner(org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner) FreeMarkerConfigurer(org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfigurer) FreeMarkerViewResolver(org.springframework.web.reactive.result.view.freemarker.FreeMarkerViewResolver) Locale(java.util.Locale) Duration(java.time.Duration) MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) View(org.springframework.web.reactive.result.view.View) FreeMarkerViewResolver(org.springframework.web.reactive.result.view.freemarker.FreeMarkerViewResolver) MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) View(org.springframework.web.reactive.result.view.View)

Aggregations

FreeMarkerViewResolver (org.springframework.web.reactive.result.view.freemarker.FreeMarkerViewResolver)2 StringWriter (java.io.StringWriter)1 Duration (java.time.Duration)1 Locale (java.util.Locale)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Test (org.junit.jupiter.api.Test)1 AutoConfigurations (org.springframework.boot.autoconfigure.AutoConfigurations)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 ConditionalOnProperty (org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)1 ReactiveWebApplicationContextRunner (org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner)1 ApplicationContext (org.springframework.context.ApplicationContext)1 Bean (org.springframework.context.annotation.Bean)1 MediaType (org.springframework.http.MediaType)1 MockServerHttpRequest (org.springframework.mock.http.server.reactive.MockServerHttpRequest)1 MockServerWebExchange (org.springframework.mock.web.server.MockServerWebExchange)1 View (org.springframework.web.reactive.result.view.View)1 FreeMarkerConfig (org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfig)1 FreeMarkerConfigurer (org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfigurer)1 Mono (reactor.core.publisher.Mono)1