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
/mvnw-spring-boot:run
工作正常JAR
:java-jarmyapp-0.0.1-SNAPSHOT0.JAR
正确启动,但不会呈现上述页面- 已执行
或/mvnw clean包
/mvnw clean安装
JAR
文件
myApp-0.0.1-SNAPSHOT.jar
大小为42MBmyApp-0.0.1-SNAPSHOT.jar.original
大小为684K
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
}
}