Maven 无法使用JAR访问运行Spring Boot的模板

Maven 无法使用JAR访问运行Spring Boot的模板,maven,spring-boot,command-line,jar,thymeleaf,Maven,Spring Boot,Command Line,Jar,Thymeleaf,我必须使用它的JAR在命令行上运行Spring引导。我已经看到了很多关于“胖罐子”的话题,我相信我已经创建了它 该程序使用SpringBoot+Maven+Thymeleaf+SpringSecurity 问题 Templates文件夹中的模板-即/resources/Templates/正确显示(我已测试并运行index.html、login.html和understruction.html) 子文件夹中的模板(即/resources/Templates/client/edit.html或/

我必须使用它的
JAR
在命令行上运行Spring引导。我已经看到了很多关于“胖罐子”的话题,我相信我已经创建了它

该程序使用SpringBoot+Maven+Thymeleaf+SpringSecurity

问题

  • Templates
    文件夹中的模板-即
    /resources/Templates/
    正确显示(我已测试并运行
    index.html
    login.html
    understruction.html
  • 子文件夹中的模板(即
    /resources/Templates/client/edit.html
    /resources/Templates/client/search.html
    )无法呈现,浏览器上显示以下错误
出现意外错误(类型=内部服务器错误,状态=500)。 解析模板“/client/add”时出错,模板可能不存在,或者任何已配置的模板解析程序都无法访问该模板

更改Spring安全配置以允许给定URL上的所有请求不会改变任何内容,因此我认为这与此无关

运行应用程序

  • 使用Maven:
    /mvnw-spring-boot:run
    工作正常
  • 使用
    JAR
    java-jarmyapp-0.0.1-SNAPSHOT0.JAR
    正确启动,但不会呈现上述页面
  • 构建JAR

    • 已执行
      /mvnw clean包
      /mvnw clean安装
    生成了2个
    JAR
    文件

  • myApp-0.0.1-SNAPSHOT.jar
    大小为42MB
  • myApp-0.0.1-SNAPSHOT.jar.original
    大小为684K
  • pom.xml文件(只是显示生成“胖罐子”的插件的一个小片段)

    
    org.springframework.boot
    springbootmaven插件
    
    随机控制器(只是为了了解他们的代码)

    @控制器
    公共类客户端控制器{
    @RequestMapping(path=“/client/search”,method=RequestMethod.GET)
    公共字符串搜索(模型){
    addAttribute(“客户端”,新客户端());
    addAttribute(“客户机”,新的ArrayList());
    返回“/客户端/搜索”;
    }
    @RequestMapping(path=“/client/add”,method=RequestMethod.GET)
    公共字符串编辑(模型){
    addAttribute(“客户端”,新客户端());
    返回“/客户端/编辑”;
    }
    }
    

    欢迎提出任何建议。

    您的问题可能是如何返回模板名称:

    @Controller
    public class ClientController {
    
        //and you could just make this simpler, like:
        //@GetMapping("/search")
        @RequestMapping(path = "/client/search", method = RequestMethod.GET)
        public String search(Model model) {
            model.addAttribute("client", new Client());
            model.addAttribute("clients", new ArrayList<Client>());
    
            return "client/search"; //NOTE: no slash
        }
    
        @RequestMapping(path = "/client/add", method = RequestMethod.GET)
        public String edit(Model model) {
            model.addAttribute("client", new Client());
            return "client/edit"; //NOTE: no slash
        }
    }
    
    @控制器
    公共类客户端控制器{
    //你可以让这更简单,比如:
    //@GetMapping(“/search”)
    @RequestMapping(path=“/client/search”,method=RequestMethod.GET)
    公共字符串搜索(模型){
    addAttribute(“客户端”,新客户端());
    addAttribute(“客户机”,新的ArrayList());
    返回“client/search”;//注意:没有斜杠
    }
    @RequestMapping(path=“/client/add”,method=RequestMethod.GET)
    公共字符串编辑(模型){
    addAttribute(“客户端”,新客户端());
    返回“client/edit”;//注意:没有斜杠
    }
    }
    
    您的问题可能是如何返回模板名称:

    @Controller
    public class ClientController {
    
        //and you could just make this simpler, like:
        //@GetMapping("/search")
        @RequestMapping(path = "/client/search", method = RequestMethod.GET)
        public String search(Model model) {
            model.addAttribute("client", new Client());
            model.addAttribute("clients", new ArrayList<Client>());
    
            return "client/search"; //NOTE: no slash
        }
    
        @RequestMapping(path = "/client/add", method = RequestMethod.GET)
        public String edit(Model model) {
            model.addAttribute("client", new Client());
            return "client/edit"; //NOTE: no slash
        }
    }
    
    @控制器
    公共类客户端控制器{
    //你可以让这更简单,比如:
    //@GetMapping(“/search”)
    @RequestMapping(path=“/client/search”,method=RequestMethod.GET)
    公共字符串搜索(模型){
    addAttribute(“客户端”,新客户端());
    addAttribute(“客户机”,新的ArrayList());
    返回“client/search”;//注意:没有斜杠
    }
    @RequestMapping(path=“/client/add”,method=RequestMethod.GET)
    公共字符串编辑(模型){
    addAttribute(“客户端”,新客户端());
    返回“client/edit”;//注意:没有斜杠
    }
    }
    
    这是确切的位置吗
    /resources/.*
    ?是的,是的。我发现了这一点,并最终删除了控制器中return语句的斜杠。这是确切的位置吗
    /resources/.*
    ?是的,它是。我发现了这个问题,并最终删除了控制器中return语句的斜杠。我在Spring Boot github中发现了这个问题——我认为现在应该解决了。我不确定这是否是正确的行为,也不确定他们是否仍然应该纠正它。非常感谢。我在Spring Boot github中发现了这个问题,我认为现在应该解决了。我不确定这是否是正确的行为,也不确定他们是否仍然应该纠正它。非常感谢。
    @Controller
    public class ClientController {
    
        //and you could just make this simpler, like:
        //@GetMapping("/search")
        @RequestMapping(path = "/client/search", method = RequestMethod.GET)
        public String search(Model model) {
            model.addAttribute("client", new Client());
            model.addAttribute("clients", new ArrayList<Client>());
    
            return "client/search"; //NOTE: no slash
        }
    
        @RequestMapping(path = "/client/add", method = RequestMethod.GET)
        public String edit(Model model) {
            model.addAttribute("client", new Client());
            return "client/edit"; //NOTE: no slash
        }
    }