【发布时间】:2018-06-01 13:09:45
【问题描述】:
我正在尝试配置第二个模板解析器以供 Thymeleaf 使用。我还想要在templates 文件夹下查看的默认解析器,但无论我尝试什么,我都只能得到一个解析器。
在我的项目中已经有一个 yaml 配置文件,其中包含:
thymeleaf:
mode: LEGACYHTML5
cache: false
作为第一步,我尝试添加一个配置 bean:
@Configuration
@EnableWebMvc
public class ThymeleafConfiguration extends WebMvcConfigurerAdapter implements ApplicationContextAware
{
private ApplicationContext applicationContext;
@Override
public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException
{
this.applicationContext = applicationContext;
}
@Bean
public TemplateEngine templateEngine() {
SpringTemplateEngine engine = new SpringTemplateEngine();
engine.setTemplateResolver(templateResolver());
return engine;
}
private ITemplateResolver templateResolver() {
SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
resolver.setApplicationContext(applicationContext);
resolver.setPrefix("/public/");
resolver.setTemplateMode("HTML");
return resolver;
}
}
但我从未在org.thymeleaf.TemplateRepository 中看到第二个解析器,只是默认的。
我进一步尝试使用以下内容修改 YAML 文件:
thymeleaf:
-
mode: LEGACYHTML5
cache: false
prefix: classpath:/public/
-
mode: LEGACYHTML5
cache: false
prefix: classpath:/templates/
但我只创建了一个解析器。
任何人都知道如何做到这一点或可以看到我做错了什么?
【问题讨论】:
标签: spring spring-boot thymeleaf