42
42
import org .springframework .web .servlet .config .annotation .WebMvcConfigurerAdapter ;
43
43
import org .springframework .web .servlet .ViewResolver ;
44
44
45
- import com .github .heneke .thymeleaf .togglz .TogglzDialect ;
46
- import org .thymeleaf .extras .springsecurity4 .dialect .SpringSecurityDialect ;
47
45
import org .thymeleaf .spring4 .SpringTemplateEngine ;
48
46
import org .thymeleaf .spring4 .view .ThymeleafView ;
49
47
import org .thymeleaf .spring4 .view .ThymeleafViewResolver ;
@@ -63,6 +61,9 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
63
61
@ Inject
64
62
private Environment env ;
65
63
64
+ @ Inject
65
+ private SpringTemplateEngine templateEngine ;
66
+
66
67
@ Override
67
68
public void configureDefaultServletHandling (DefaultServletHandlerConfigurer configurer ) {
68
69
configurer .enable ();
@@ -112,23 +113,20 @@ public Validator getValidator() {
112
113
}
113
114
114
115
// override Spring Boot default configuration
115
- @ Bean (name = "thymeleafViewResolver" )
116
- @ SuppressWarnings ("PMD.SignatureDeclareThrowsException" )
117
- public ViewResolver getThymeleafViewResolver () throws Exception {
116
+ @ Bean (name = "defaultTemplateResolver" )
117
+ public TemplateResolver getThymeleafTemplateResolver () {
118
118
TemplateResolver templateResolver = new ServletContextTemplateResolver ();
119
119
templateResolver .setTemplateMode ("HTML5" );
120
120
templateResolver .setPrefix ("/WEB-INF/views/" );
121
121
templateResolver .setSuffix (".html" );
122
122
templateResolver .setCharacterEncoding ("UTF-8" );
123
123
templateResolver .setCacheable (env .acceptsProfiles ("prod" ));
124
-
125
- SpringTemplateEngine templateEngine = new SpringTemplateEngine ();
126
- templateEngine .setTemplateResolver (templateResolver );
127
- templateEngine .setTemplateEngineMessageSource (getMessageSource ());
128
- templateEngine .addDialect (new SpringSecurityDialect ());
129
- templateEngine .addDialect (new TogglzDialect ());
130
- templateEngine .afterPropertiesSet ();
131
-
124
+ return templateResolver ;
125
+ }
126
+
127
+ // override Spring Boot default configuration
128
+ @ Bean (name = "thymeleafViewResolver" )
129
+ public ViewResolver getThymeleafViewResolver () {
132
130
ThymeleafViewResolver viewResolver = new ThymeleafViewResolver ();
133
131
viewResolver .setTemplateEngine (templateEngine );
134
132
viewResolver .setContentType ("text/html; charset=UTF-8" );
0 commit comments