我想知道什么: - thymeleaf怎么知道它返回的error.html?
两部分。首先,Spring被配置为在所有服务器端视图中使用Thymeleaf。在JHipster,应用程序注释是这样的:
@ComponentScan
@EnableAutoConfiguration(exclude = {MetricFilterAutoConfiguration.class, MetricRepositoryAutoConfiguration.class})
public class Application {
的@EnableAutoConfiguration
的关键在于理解Thymeleaf是如何设置。它触发ThymeleafAutoConfiguration创建Thymeleaf视图解析器和什么。请注意,JHipster有一个ThymeleafConfiguration
类,但这仅用于电子邮件,并且与您的问题无关。
第二部分... Spring Boot使用“/ error”作为默认错误视图。从the docs:
春天开机默认提供的/错误映射,处理在一个合理的方式,所有 错误,并已被注册为在servlet容器中的“全球性”的错误 页。对于机器客户端,它将生成一个 JSON响应,其中包含错误,HTTP状态和异常消息的详细信息。对于浏览器客户端,有一个'whitelabel'错误 视图呈现HTML格式的相同数据(要自定义它,只需添加一个视图,解析为'错误')。
解析错误视图时,Spring会为您正在使用的视图解析器添加正确的后缀(我描述的第一部分)。例如,Thymleaf的.html,Velocity的.vm或Freemarker的.ftl。
某处是否有某种服务器端控制器?
是的。 JHipster也在使用Spring Boot Actuator。退房this section of the docs。感兴趣的主要类别是ErrorMvcAutoConfiguration。具体来说这部分:
@Bean
@ConditionalOnMissingBean(value = ErrorAttributes.class, search = SearchStrategy.CURRENT)
public DefaultErrorAttributes errorAttributes() {
return new DefaultErrorAttributes();
}
@Bean
@ConditionalOnMissingBean(value = ErrorController.class, search = SearchStrategy.CURRENT)
public BasicErrorController basicErrorController(ErrorAttributes errorAttributes) {
return new BasicErrorController(errorAttributes);
}
哪里来从(同一状态和消息)错误?
见我上面刚刚提到的,然后看看在DefaultErrorAttributes代码:
Map<String, Object> errorAttributes = new LinkedHashMap<String, Object>();
errorAttributes.put("timestamp", new Date());
// and so on...
另一个问题是一个推论:为什么会出现2个错误页面中 jhipster,一个客户端和一个服务器?由于JHipster用于SPA,因此不应该只有一个 客户端页面。为什么服务器 总是发回index.html,让客户端测试是否存在 错误?
需要有一个服务器端错误处理程序。并非所有的东西都会映射到角度路线。例如,www.yoursite.com/doesnt_exist会导致浏览器向服务器发出另一个请求。
最后一个问题是一个推论太:是有一些方法要求在客户端(角) 路由 动态服务器端(thymeleaf)模板(在app.js文件)。这对于开发丰富的SPA有很大的帮助。
是的。你可以在app.js中为templateUrl
指定一个JS函数。