Modified code to support both thymeleaf and existing viewResolvers

This commit is contained in:
vkadapa 2015-12-18 07:14:51 +05:30
parent 1e91b46d1e
commit 7fef269169
1 changed files with 14 additions and 7 deletions

View File

@ -15,6 +15,8 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
import org.thymeleaf.dialect.IDialect; import org.thymeleaf.dialect.IDialect;
import org.thymeleaf.spring4.SpringTemplateEngine; import org.thymeleaf.spring4.SpringTemplateEngine;
import org.thymeleaf.spring4.view.ThymeleafViewResolver; import org.thymeleaf.spring4.view.ThymeleafViewResolver;
@ -39,18 +41,23 @@ public class ClientWebConfig extends WebMvcConfigurerAdapter {
} }
@Bean @Bean
public ViewResolver viewResolver() { public ViewResolver thymeleafViewResolver() {
/*final InternalResourceViewResolver bean = new InternalResourceViewResolver();
bean.setViewClass(JstlView.class);
bean.setPrefix("/WEB-INF/view/");
bean.setSuffix(".jsp");*/
final ThymeleafViewResolver viewResolver = new ThymeleafViewResolver(); final ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
viewResolver.setTemplateEngine(templateEngine()); viewResolver.setTemplateEngine(templateEngine());
viewResolver.setOrder(1);
return viewResolver; return viewResolver;
} }
@Bean
public ViewResolver viewResolver() {
final InternalResourceViewResolver bean = new InternalResourceViewResolver();
bean.setViewClass(JstlView.class);
bean.setPrefix("/WEB-INF/view/");
bean.setSuffix(".jsp");
bean.setOrder(0);
return bean;
}
@Bean @Bean
@Description("Thymeleaf template resolver serving HTML 5") @Description("Thymeleaf template resolver serving HTML 5")
public ServletContextTemplateResolver templateResolver() { public ServletContextTemplateResolver templateResolver() {