java - 加载 html 页面时出现 Thymeleaf TemplateInputException

标签 java spring spring-boot thymeleaf

我有一个 html 页面,我在其中使用 jQuery 从 Spring Boot 应用程序加载页面内容

这是项目结构

structure of my project

我使用 zuul 作为代理,我对我的项目中的 Zuul Eureka 配置充满信心

当我尝试通过在浏览器中调用 localhost:9999/facturation 来访问我的根项目页面 (facturation.html) 时,出现以下异常

org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "root folder where all thymeleaf files/facturation.html")

Caused by: java.io.FileNotFoundException: ClassLoader resource "root folder where all thymeleaf files/facturation.html" could not be resolved at org.thymeleaf.templateresource.ClassLoaderTemplateResource.reader(ClassLoaderTemplateResource.java:130) ~[thymeleaf-3.0.6.RELEASE.jar:3.0.6.RELEASE] at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:223) ~[thymeleaf-3.0.6.RELEASE.jar:3.0.6.RELEASE]

java.io.FileNotFoundException: ClassLoader resource "root folder where all thymeleaf files/facturation.html" could not be resolved

我的 Spring Controller 如下

    @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;
    }
    
}

我的facuration.htl页面是

<!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,我的服务名为facuration,这就是为什么我在 zuul 地址后添加facuration,以便他知道要联系哪个服务

最佳答案

使用这个question我配置了 thymeleaf 从类路径获取我的页面

关于java - 加载 html 页面时出现 Thymeleaf TemplateInputException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53264486/

相关文章:

java - 触发 Jenkins 作业时动态设置 cucumber 标签

java - 找不到类 java.util.logging.ErrorManager 的序列化程序,也没有发现用于创建 BeanSerializer 的属性

java - org.springframework.beans.factory.NoSuchBeanDefinitionException : No bean named 'BookDao' is defined

spring - 用 java 8 lambda 表达式替换 RowMapper 对象

java - CAS-SSO 和 Spring Security (Spring Boot) 中的无限重定向登录循环

spring - 如何在独立的 Turbine 应用程序中激活/turbine.stream 端点

java - 无法从 JSON 转换;意外字符 ('f'(代码 102)): Expected space separating root-level values at (String )"5f19a7e99933db43cb23e83d"

java - 高负载下 Java Beanshell 解释器中的锁争用

java - 如何查找并跳过单词开头和结尾的特殊字符

java - Spring 启动: MySQLNonTransientConnectionException: Could not create connection