001package io.jstach.opt.spring.webflux.example; 002 003import org.springframework.beans.factory.annotation.Autowired; 004import org.springframework.context.ApplicationContext; 005import org.springframework.context.annotation.Bean; 006import org.springframework.context.annotation.Configuration; 007import org.springframework.http.codec.ServerCodecConfigurer; 008import org.springframework.web.reactive.config.WebFluxConfigurer; 009 010import io.jstach.jstachio.JStachio; 011import io.jstach.opt.spring.web.JStachioHttpMessageConverter; 012import io.jstach.opt.spring.webflux.JStachioEncoder; 013import io.jstach.opt.spring.webflux.JStachioModelViewConfigurer; 014import io.jstach.opt.spring.webflux.ViewSetupBeanPostProcessor; 015 016/** 017 * Configures MVC using {@link JStachioHttpMessageConverter} to allow returning models 018 * which will be rendered using JStachio runtime. 019 * 020 * @author agentgt 021 * @see JStachioHttpMessageConverter 022 */ 023@SuppressWarnings("exports") 024@Configuration 025public class WebConfig implements WebFluxConfigurer { 026 027 private final JStachio jstachio; 028 029 /** 030 * Configures based on the jstachio found by spring 031 * @param jstachio the found jstachio 032 */ 033 @Autowired 034 public WebConfig(JStachio jstachio) { 035 this.jstachio = jstachio; 036 } 037 038 @Override 039 public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) { 040 configurer.customCodecs().register(new JStachioEncoder(jstachio)); 041 } 042 043 /** 044 * Factory to create a bean post processor to register 045 * {@link JStachioModelViewConfigurer}s. 046 * @param context supplied by spring 047 * @return a post processor that will configure JStachio Model Views before being 048 * rendered. 049 */ 050 @Bean 051 public ViewSetupBeanPostProcessor viewSetupHandlerInterceptor(ApplicationContext context) { 052 return new ViewSetupBeanPostProcessor(context); 053 } 054 055}