sts 控制台中没有错误消息的 WhiteLabel 错误页面
Posted
技术标签:
【中文标题】sts 控制台中没有错误消息的 WhiteLabel 错误页面【英文标题】:WhiteLabel Error page with no error message in sts console 【发布时间】:2021-04-20 00:13:46 【问题描述】:我正在按照《Spring in action》第五版一书制作基本应用程序的第一步。但是现在我在浏览器中看到以下错误消息,并且控制台中没有打印任何日志。下面是代码:
控制器方法:
@Controller
@RequestMapping("/design")
public class DesignTacoController
@GetMapping
public String showDesignForm(Model model)
List<Ingredient> ingredients = Arrays.asList(new Ingredient("FLTO", "Flour Tortilla", Ingredient.Type.WRAP),
new Ingredient("COTO", "Corn Tortilla", Ingredient.Type.WRAP),
new Ingredient("GRBF", "Ground Beef", Ingredient.Type.PROTEIN),
new Ingredient("CARN", "Carnitas", Ingredient.Type.PROTEIN),
new Ingredient("TMTO", "Diced Tomatoes", Ingredient.Type.VEGGIES),
new Ingredient("LETC", "Lettuce", Ingredient.Type.VEGGIES),
new Ingredient("CHED", "Cheddar", Ingredient.Type.CHEESE),
new Ingredient("JACK", "Monterrey Jack", Ingredient.Type.CHEESE),
new Ingredient("SLSA", "Salsa", Ingredient.Type.SAUCE),
new Ingredient("SRCR", "Sour Cream", Ingredient.Type.SAUCE));
Type[] types = Ingredient.Type.values();
for (Type type : types)
model.addAttribute(type.toString().toLowerCase(),
filterByType(ingredients, type));
model.addAttribute("tacodesign", new Taco());
return "tacodesign";
private List<Ingredient> filterByType(List<Ingredient> ingredients, Type type)
return ingredients.stream().filter(x -> x.getType().equals(type)).collect(Collectors.toList());
@Bean
public ViewResolver getViewResolver()
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("templates/");
//resolver.setSuffix(".html");
return resolver;
型号:
package com.example.demo.taco.model;
import lombok.Data;
import lombok.RequiredArgsConstructor;
@Data
@RequiredArgsConstructor
public class Ingredient
private String id;
private String name;
private Type type;
public static enum Type
WRAP, PROTEIN, VEGGIES, CHEESE, SAUCE
public Ingredient(String id, String name, Type type)
this.id = id;
this.name = name;
this.type = type;
public String getId()
return id;
public String getName()
return name;
public Type getType()
return type;
查看(使用百里香叶):
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Taco Cloud</title>
<link rel="stylesheet" th:href="@/styles.css" />
</head>
<body>
<h1>Design your taco!</h1>
<img th:src="@/images/TacoCloud.png" />
<form method="POST" th:object="$tacodesign">
<div class="grid">
<div class="ingredient-group" id="wraps">
<h3>Designate your wrap:</h3>
<div th:each="ingredient : $wrap">
<input name="ingredients" type="checkbox"
th:value="$ingredient.id" /> <span
th:text="$ingredient.name">INGREDIENT</span><br />
</div>
</div>
<div class="ingredient-group" id="proteins">
<h3>Pick your protein:</h3>
<div th:each="ingredient : $protein">
<input name="ingredients" type="checkbox"
th:value="$ingredient.id" /> <span
th:text="$ingredient.name">INGREDIENT</span><br />
</div>
</div>
<div class="ingredient-group" id="cheeses">
<h3>Choose your cheese:</h3>
<div th:each="ingredient : $cheese">
<input name="ingredients" type="checkbox"
th:value="$ingredient.id" /> <span
th:text="$ingredient.name">INGREDIENT</span><br />
</div>
</div>
<div class="ingredient-group" id="veggies">
<h3>Determine your veggies:</h3>
<div th:each="ingredient : $veggies">
<input name="ingredients" type="checkbox"
th:value="$ingredient.id" /> <span
th:text="$ingredient.name">INGREDIENT</span><br />
</div>
</div>
<div class="ingredient-group" id="sauces">
<h3>Select your sauce:</h3>
<div th:each="ingredient : $sauce">
<input name="ingredients" type="checkbox"
th:value="$ingredient.id" /> <span
th:text="$ingredient.name">INGREDIENT</span><br />
</div>
</div>
</div>
<div>
<h3>Name your taco creation:</h3>
<input type="text" th:field="*name" /><br/>
<button>Submit your taco</button>
</div>
</form>
</body>
</html>
SpringBootStarter:
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TacoCloudApplication
public static void main(String[] args)
SpringApplication.run(TacoCloudApplication.class, args);
以下是文件夹结构截图:
错误截图:
我从下面的链接中获取了一些输入,它确实帮助我消除了旧的错误,但现在我被这个错误困住了。 Error resolving template "index", template might not exist or might not be accessible by any of the configured Template Resolvers How to avoid the "Circular view path" exception with Spring MVC test
【问题讨论】:
【参考方案1】:问题是您需要在控制器中提供正确的模板作为showDesignForm
的返回值。
请返回TacoHome
而不是tacodesign
:
@GetMapping
public String showDesignForm(Model model)
List<Ingredient> ingredients = Arrays.asList(new Ingredient("FLTO", "Flour Tortilla", Ingredient.Type.WRAP),
new Ingredient("COTO", "Corn Tortilla", Ingredient.Type.WRAP),
new Ingredient("GRBF", "Ground Beef", Ingredient.Type.PROTEIN),
new Ingredient("CARN", "Carnitas", Ingredient.Type.PROTEIN),
new Ingredient("TMTO", "Diced Tomatoes", Ingredient.Type.VEGGIES),
new Ingredient("LETC", "Lettuce", Ingredient.Type.VEGGIES),
new Ingredient("CHED", "Cheddar", Ingredient.Type.CHEESE),
new Ingredient("JACK", "Monterrey Jack", Ingredient.Type.CHEESE),
new Ingredient("SLSA", "Salsa", Ingredient.Type.SAUCE),
new Ingredient("SRCR", "Sour Cream", Ingredient.Type.SAUCE));
Type[] types = Ingredient.Type.values();
for (Type type : types)
model.addAttribute(type.toString().toLowerCase(),
filterByType(ingredients, type));
model.addAttribute("tacodesign", new Taco());
// Set the template name to the appropriate value
// Generally speaking, it should match a file name in the
// templates directory, without the extension
return "TacoHome";
【讨论】:
我尝试了解决方案,但仍然遇到相同的错误。之前,我尝试重命名我的视图以匹配之前的返回,但在这两种情况下都出现了现有错误。 对不起,在其他帖子的答案之一中,要求在 application.properties 中添加以下内容: spring.thymeleaf.enabled=false 我已删除,现在我可以正确获取视图。谢谢!! 欢迎您@AbhinashJha。没有必要感到抱歉。我很高兴现在该应用程序运行正常。以上是关于sts 控制台中没有错误消息的 WhiteLabel 错误页面的主要内容,如果未能解决你的问题,请参考以下文章
STS 启动错误 - Java 已启动但返回退出代码 = 13