我的配置有一个奇怪的问题。我正在尝试用百里香来配置apache瓷砖。我正在努力做他们在documentation page上做的事情。
我有以下配置文件:
@Configuration
public class ViewConfig {
@Bean
public ViewResolver tilesViewResolver() {
ThymeleafViewResolver vr = new ThymeleafViewResolver();
vr.setTemplateEngine(templateEngine());
vr.setViewClass(ThymeleafTilesView.class);
vr.setCharacterEncoding("UTF-8");
vr.setOrder(Ordered.LOWEST_PRECEDENCE);
return vr;
}
@Bean
public ViewResolver thymeleafViewResolver() {
ThymeleafViewResolver vr = new ThymeleafViewResolver();
vr.setTemplateEngine(templateEngine());
vr.setCharacterEncoding("UTF-8");
vr.setOrder(Ordered.HIGHEST_PRECEDENCE);
// all message/* views will not be handled by this resolver;
vr.setExcludedViewNames(new String[]{"message/*"});
return vr;
}
@Bean
public SpringTemplateEngine templateEngine() {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.addDialect(new TilesDialect());
templateEngine.setTemplateResolver(templateResolver());
return templateEngine;
}
@Bean
public ThymeleafTilesConfigurer tilesConfigurer() {
ThymeleafTilesConfigurer ttc = new ThymeleafTilesConfigurer();
ttc.setValidateDefinitions(false);
ttc.setDefinitions(new String[]{"/templates/tiles-defs.xml"});
return ttc;
}
@Bean
public TemplateResolver templateResolver() {
ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
resolver.setSuffix(".html");
resolver.setPrefix("templates/");
resolver.setTemplateMode("HTML5");
resolver.setCharacterEncoding("UTF-8");
return resolver;
}
}
我已经为我的目的添加了TemplateResolver,但删除它并没有帮助(因为具有与文档相同的配置)。
这是我的资源文件夹结构:
问题是我有以下异常:
Caused by: java.io.FileNotFoundException: ServletContext resource [/templates/tiles-defs.xml] cannot be resolved to URL because it does not exist
最有趣的是我检查了target/classes
(在类路径中)并且有文件templates/tiles-defs.xml
。
我已经尝试了几次更改定义路径(我也试图删除定义并从默认的WEB-INF/tiles.xml
路径获取它)但没有结果 - 同样的例外。
我做错了什么?
答案 0 :(得分:0)
以下是我解决它的方法:
@Bean
public ThymeleafTilesConfigurer tilesConfigurer() {
ThymeleafTilesConfigurer ttc = new ThymeleafTilesConfigurer();
//ttc.setValidateDefinitions(false);
ttc.setDefinitions(ThymeleafProperties.DEFAULT_PREFIX + "tiles-defs.xml");
return ttc;
}