Spring-部署 WAR 时引导模板解析失败
Spring-Boot template resolution fails when WAR is deployed
我的 Spring-Boot 应用程序在 运行 通过 Eclipse IDE(安装了 S.T.S.3.8.4)时工作正常,带有嵌入式 tomcat服务器。
我将其打包为 WAR 并部署到本地 Tomcat 服务器。
访问应用程序时,返回空白页面。我在 Tomcat 日志中发现了异常(在 Windows、C:\<path-to-tomcat>\logs
上)尝试解析 Thymeleaf 模板时抛出异常:
2017-04-04 12:33:36.602 ERROR 5724 --- [io-12080-exec-7] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-12080-exec-7] Exception processing template "home": Error resolving template "common/layout", template might not exist or might not be accessible by any of the configured Template Resolvers (template: "home" - line 5, col 7)
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "common/layout", template might not exist or might not be accessible by any of the configured Template Resolvers (template: "home" - line 5, col 7)
at org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:865) ~[thymeleaf-3.0.2.RELEASE.jar:3.0.2.RELEASE]
问题出在文件夹名称的大小写上。
我在 templates/Common/layout.html
中有我的布局片段(注意 Common 中的大写字母 C)并且在我看来引用了 common/layout
,它在 IDE 中工作,但没有工作在 Tomcat 服务器上部署 WAR 时。可能是因为 IDE 忽略大小写,而 Tomcat 区分大小写?
将我认为的引用更改为文件夹的正确大小写后它起作用了,Common/layout
我的 Spring-Boot 应用程序在 运行 通过 Eclipse IDE(安装了 S.T.S.3.8.4)时工作正常,带有嵌入式 tomcat服务器。
我将其打包为 WAR 并部署到本地 Tomcat 服务器。
访问应用程序时,返回空白页面。我在 Tomcat 日志中发现了异常(在 Windows、C:\<path-to-tomcat>\logs
上)尝试解析 Thymeleaf 模板时抛出异常:
2017-04-04 12:33:36.602 ERROR 5724 --- [io-12080-exec-7] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-12080-exec-7] Exception processing template "home": Error resolving template "common/layout", template might not exist or might not be accessible by any of the configured Template Resolvers (template: "home" - line 5, col 7)
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "common/layout", template might not exist or might not be accessible by any of the configured Template Resolvers (template: "home" - line 5, col 7)
at org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:865) ~[thymeleaf-3.0.2.RELEASE.jar:3.0.2.RELEASE]
问题出在文件夹名称的大小写上。
我在 templates/Common/layout.html
中有我的布局片段(注意 Common 中的大写字母 C)并且在我看来引用了 common/layout
,它在 IDE 中工作,但没有工作在 Tomcat 服务器上部署 WAR 时。可能是因为 IDE 忽略大小写,而 Tomcat 区分大小写?
将我认为的引用更改为文件夹的正确大小写后它起作用了,Common/layout