@ -26,15 +26,17 @@ import javax.servlet.Servlet;
import nz.net.ultraq.thymeleaf.LayoutDialect ;
import nz.net.ultraq.thymeleaf.LayoutDialect ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.boot.autoconfigure.AutoConfigureAfter ;
import org.springframework.boot.autoconfigure.AutoConfigureAfter ;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration ;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration ;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass ;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass ;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean ;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean ;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration ;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration ;
import org.springframework.boot.bind.RelaxedPropertyResolver ;
import org.springframework.context.EnvironmentAware ;
import org.springframework.context.annotation.Bean ;
import org.springframework.context.annotation.Bean ;
import org.springframework.context.annotation.Configuration ;
import org.springframework.context.annotation.Configuration ;
import org.springframework.core.Ordered ;
import org.springframework.core.Ordered ;
import org.springframework.core.env.Environment ;
import org.springframework.core.io.DefaultResourceLoader ;
import org.springframework.core.io.DefaultResourceLoader ;
import org.springframework.core.io.ResourceLoader ;
import org.springframework.core.io.ResourceLoader ;
import org.thymeleaf.TemplateProcessingParameters ;
import org.thymeleaf.TemplateProcessingParameters ;
@ -58,22 +60,19 @@ public class ThymeleafAutoConfiguration {
@Configuration
@Configuration
@ConditionalOnMissingBean ( name = "defaultTemplateResolver" )
@ConditionalOnMissingBean ( name = "defaultTemplateResolver" )
protected static class DefaultTemplateResolverConfiguration {
protected static class DefaultTemplateResolverConfiguration implements
EnvironmentAware {
@Autowired
@Autowired
private ResourceLoader resourceLoader = new DefaultResourceLoader ( ) ;
private ResourceLoader resourceLoader = new DefaultResourceLoader ( ) ;
@Value ( "${spring.template.prefix:classpath:/templates/}" )
private RelaxedPropertyResolver environment ;
private String prefix = "classpath:/templates/" ;
@Value ( "${spring.template.suffix:.html}" )
@Override
private String suffix = ".html" ;
public void setEnvironment ( Environment environment ) {
this . environment = new RelaxedPropertyResolver ( environment ,
@Value ( "${spring.template.cache:true}" )
"spring.thymeleaf." ) ;
private boolean cacheable ;
}
@Value ( "${spring.template.mode:HTML5}" )
private String templateMode = "HTML5" ;
@Bean
@Bean
public ITemplateResolver defaultTemplateResolver ( ) {
public ITemplateResolver defaultTemplateResolver ( ) {
@ -97,10 +96,12 @@ public class ThymeleafAutoConfiguration {
return "SPRING" ;
return "SPRING" ;
}
}
} ) ;
} ) ;
resolver . setPrefix ( this . prefix ) ;
resolver . setPrefix ( this . environment . getProperty ( "prefix" ,
resolver . setSuffix ( this . suffix ) ;
"classpath:/templates/" ) ) ;
resolver . setTemplateMode ( this . templateMode ) ;
resolver . setSuffix ( this . environment . getProperty ( "suffix" , ".html" ) ) ;
resolver . setCacheable ( this . cacheable ) ;
resolver . setTemplateMode ( this . environment . getProperty ( "mode" , "HTML5" ) ) ;
resolver . setCacheable ( this . environment . getProperty ( "cache" , Boolean . class ,
true ) ) ;
return resolver ;
return resolver ;
}
}