org.mockserver.examples.proxy.web.configuration.WebMvcConfiguration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockserver-examples Show documentation
Show all versions of mockserver-examples Show documentation
An example project demonstration tests using the mock server and proxy
package org.mockserver.examples.proxy.web.configuration;
import freemarker.cache.ClassTemplateLoader;
import freemarker.cache.MultiTemplateLoader;
import freemarker.cache.TemplateLoader;
import freemarker.template.TemplateExceptionHandler;
import org.mockserver.model.MediaType;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfig;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
/**
* @author jamesdbloom
*/
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"org.mockserver.examples.proxy.web"})
public class WebMvcConfiguration extends WebMvcConfigurerAdapter {
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
@Bean
public FreeMarkerConfigurer freemarkerConfig() {
FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
freeMarkerConfigurer.setConfiguration(new freemarker.template.Configuration(freemarker.template.Configuration.VERSION_2_3_22) {{
setTemplateLoader(new MultiTemplateLoader(
new TemplateLoader[]{
new ClassTemplateLoader(FreeMarkerConfig.class, "/")
}
));
setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
setWhitespaceStripping(true);
}});
return freeMarkerConfigurer;
}
@Bean
public FreeMarkerViewResolver freeMarkerViewResolver() {
FreeMarkerViewResolver freeMarkerViewResolver = new FreeMarkerViewResolver();
freeMarkerViewResolver.setOrder(1);
freeMarkerViewResolver.setPrefix("view/");
freeMarkerViewResolver.setSuffix(".ftl");
freeMarkerViewResolver.setContentType(MediaType.HTML_UTF_8.toString());
return freeMarkerViewResolver;
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
}