java - 加载html页面时的Thymeleaf TemplateInputException
问题描述
我有一个 html 页面,我在其中使用 jQuery 从 Spring Boot 应用程序加载页面内容
这是项目结构
我正在使用 zuul 作为代理我对我的项目中的 Zuul Eureka 配置很有信心
当我尝试通过在浏览器中调用 localhost:9999/facturation 来访问我的根项目页面(facturation.html)时,出现以下异常
org.thymeleaf.exceptions.TemplateInputException:模板解析期间发生错误(模板:“所有百里香文件/facturation.html的根文件夹”)
原因:java.io.FileNotFoundException:ClassLoader 资源“所有 thymeleaf 文件/facturation.html 所在的根文件夹”无法在 org.thymeleaf.templateresource.ClassLoaderTemplateResource.reader(ClassLoaderTemplateResource.java:130) ~[thymeleaf-3.0. 6.RELEASE.jar:3.0.6.RELEASE] 在 org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:223) ~[thymeleaf-3.0.6.RELEASE.jar:3.0.6.RELEASE]
java.io.FileNotFoundException:ClassLoader 资源“无法解析所有 thymeleaf 文件/facturation.html 的根文件夹”
我的弹簧控制器如下
@Controller
public class LandingController {
private static final Logger log = LoggerFactory.getLogger(LandingController.class);
@Autowired
private AppClientFeign appClientFeign;
@Autowired
private UserClientFeign userClientFeign;
@RequestMapping("/")
String home(Model model,Principal principal) {
List<Menu> appMenus = appClientFeign.getAppMenus("facturation");
model.addAttribute("applications", appClientFeign.getApps());
model.addAttribute("applicationsHistory", appClientFeign.getAppsHistory(principal.getName()));
model.addAttribute("currentUser", userClientFeign.getUserDetails(principal.getName()));
if(log.isDebugEnabled()) {
StringBuilder stringBuilder2 = new StringBuilder();
stringBuilder2.append(appMenus);
stringBuilder2.append("");
log.debug(stringBuilder2.toString());
}
model.addAttribute("menuV", appMenus);
model.addAttribute("addClientObject", AddClientDTO.builder().build());
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(" hello world ****************** ---------------------- ************************ \n \n \n");
stringBuilder.append(appClientFeign.getApps());
if(log.isDebugEnabled())log.debug(stringBuilder.toString());
return "facturation";
}
@RequestMapping("/html/{page}")
String resolveHTML(Model model,Principal principal,@PathVariable String page) {
List<Menu> appMenus = appClientFeign.getAppMenus("facturation");
model.addAttribute("applications", appClientFeign.getApps());
model.addAttribute("applicationsHistory", appClientFeign.getAppsHistory(principal.getName()));
model.addAttribute("currentUser", userClientFeign.getUserDetails(principal.getName()));
if(log.isDebugEnabled()) {
StringBuilder stringBuilder2 = new StringBuilder();
stringBuilder2.append(appMenus);
stringBuilder2.append("");
log.debug(stringBuilder2.toString());
}
model.addAttribute("menuV", appMenus);
model.addAttribute("addClientObject", AddClientDTO.builder().build());
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(" hello world ****************** ---------------------- ************************ \n \n \n");
stringBuilder.append(appClientFeign.getApps());
if(log.isDebugEnabled())log.debug(stringBuilder.toString());
return page;
}
@RequestMapping("/html/{folder}/{page}")
String resolveHTML(Model model,Principal principal,@PathVariable String page,@PathVariable String folder) {
List<Menu> appMenus = appClientFeign.getAppMenus("facturation");
model.addAttribute("applications", appClientFeign.getApps());
model.addAttribute("applicationsHistory", appClientFeign.getAppsHistory(principal.getName()));
model.addAttribute("currentUser", userClientFeign.getUserDetails(principal.getName()));
if(log.isDebugEnabled()) {
StringBuilder stringBuilder2 = new StringBuilder();
stringBuilder2.append(appMenus);
stringBuilder2.append("");
log.debug(stringBuilder2.toString());
}
model.addAttribute("menuV", appMenus);
model.addAttribute("addClientObject", AddClientDTO.builder().build());
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(" hello world ****************** ---------------------- ************************ \n \n \n");
stringBuilder.append(appClientFeign.getApps());
if(log.isDebugEnabled())log.debug(stringBuilder.toString());
return folder+"/"+page;
}
}
我的facturation.html页面是
<!DOCTYPE HTML>
<html lang="fr">
<head>
<meta charset="UTF-8"/>
<title>Facturation - MDS</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="http://localhost:9999/MDS-WEB-RESSOURCE/js/loader.js"></script>
<script src="http://localhost:9999/MDS-WEB-RESSOURCE/js/main.js"></script>
<script src="http://localhost:9999/MDS-WEB-RESSOURCE/js/facturation.js"></script>
<script src="http://localhost:9999/MDS-WEB-RESSOURCE/js/chart.js"></script>
<script src="http://localhost:9999/MDS-WEB-RESSOURCE/js/menus.js"></script>
<script src="http://localhost:9999/MDS-WEB-RESSOURCE/js/grid.js"></script>
<script src="http://localhost:9999/MDS-WEB-RESSOURCE/js/tab.js"></script>
<script src="http://localhost:9999/MDS-WEB-RESSOURCE/js/notify.js"></script>
<script src="http://localhost:9999/MDS-WEB-RESSOURCE/js/print.js"></script>
<script src="http://localhost:9999/MDS-WEB-RESSOURCE/js/check.js"></script>
<script onloadstart="loadAdditionalData()" src="http://localhost:9999/MDS-WEB-RESSOURCE/js/facturationLoader.js"></script>
<link rel="stylesheet" type="text/css" href="http://localhost:9999/MDS-WEB-RESSOURCE/css/main.css"/>
<link rel="stylesheet" type="text/css" href="http://localhost:9999/MDS-WEB-RESSOURCE/css/facturation.css"/>
<link rel="stylesheet" type="text/css" href="http://localhost:9999/MDS-WEB-RESSOURCE/css/chart.css"/>
<link rel="stylesheet" type="text/css" href="http://localhost:9999/MDS-WEB-RESSOURCE/css/grid.css"/>
<link rel="stylesheet" type="text/css" href="http://localhost:9999/MDS-WEB-RESSOURCE/css/tab.css"/>
<link rel="stylesheet" type="text/css" href="http://localhost:9999/MDS-WEB-RESSOURCE/css/notify.css"/>
<link rel="stylesheet" type="text/css" href="http://localhost:9999/MDS-WEB-RESSOURCE/css/menus.css"/>
<link rel="stylesheet" type="text/css" href="http://localhost:9999/MDS-WEB-RESSOURCE/css/dropdown.css"/>
<link rel="stylesheet" type="text/css" href="http://localhost:9999/MDS-WEB-RESSOURCE/css/check.css"/>
</head>
<body>
<div id="overlay" class="overlay">
<div class="form-container">
</div>
</div>
<div style="height: 100%;">
<div id="header" class="header">
</div>
<div id="menu0" class="menu-V">
</div>
<div class="container">
<div id="menu0-func0-panel" class="main-panel" style="display: block;">
</div>
<div id="menu0-func1-panel" class="main-panel">
</div>
<div id="menu0-func2-panel" class="main-panel">
</div>
<div id="menu0-func3-panel" class="main-panel">
</div>
</div>
</div>
</body>
</html>
最后 loader.js 如下
$(document).ready(function() {
$("#header").load("http://"+document.location.host+"/facturation/html/facturation-header");
$("#menu0").load("http://"+document.location.host+"/facturation/html/facturation-menu0");
$("#menu0-func0-panel").load("http://"+document.location.host+"/facturation/html/facturation-menu0-func0-panel", function() {
var option={
parent: "#stat-container",
type: "Pie",
labels: ['FACTURES EN ATTENTE', 'FACTURES EN RETARD (- DE 30 JOURS)', 'FACTURES EN RETARD (+ DE 30 JOURS)'],
data: [20, 15, 10],
colors: ["#0ae1ff", "#067180", "#dd4d40"],
canvasWidth: 250,
canvasHeight: 250,
legendType: "value",
legendPosition: "bottom",
legendUnit: "DZD",
overlay: false
};
chart(option);
});
$("#menu0-func1-panel").load("http://"+document.location.host+"/facturation/html/facturation-menu0-func1-panel");
$("#menu0-func2-panel").load("http://"+document.location.host+"/facturation/html/facturation-menu0-func2-panel");
$("#menu0-func3-panel").load("http://"+document.location.host+"/facturation/html/facturation-menu0-func3-panel");
});
老实说,我一点也不知道为什么会得到这个,也不知道我应该做什么或尝试什么。
注意:我正在使用前面提到的 zuul 和 eureka,我的服务被命名为 facturation,这就是为什么我在 zuul 地址之后添加了facturation,这样他就知道要联系哪个服务
解决方案
使用这个问题,我配置 thymeleaf 以从类路径中获取我的页面
推荐阅读
- time - 为什么在 Python 中使用 zip 执行“for 循环”的时间在两个等效上下文中不大致相同
- c++ - Qt 全局快捷方式扩展劫持快捷方式
- tensorflow - 使用模型中生成的目标数据进行训练
- spring-boot - Spring avro 消费者消息转换器异常
- google-play - 我未满 18 岁,我可以将我的项目上传到 Google Play 商店吗?
- python - 按键排序字典列表。如果 key 缺失,假设一个连续的编号
- amazon-web-services - 如何获取api网关触发的lambda函数的id?
- ruby - 使用 Jekyll-compose 时,我无法为草稿或帖子设置默认的前端
- wpf - WPF 中的拖放事件是否可能不可靠地触发?
- git - 通过命令行停用 Git 预提交挂钩