本文整理汇总了Java中org.springframework.boot.autoconfigure.web.DefaultErrorAttributes类的典型用法代码示例。如果您正苦于以下问题:Java DefaultErrorAttributes类的具体用法?Java DefaultErrorAttributes怎么用?Java DefaultErrorAttributes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DefaultErrorAttributes类属于org.springframework.boot.autoconfigure.web包,在下文中一共展示了DefaultErrorAttributes类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: errorAttributes
import org.springframework.boot.autoconfigure.web.DefaultErrorAttributes; //导入依赖的package包/类
/**
* Customized ErrorAttribute bean.
* We really need to find a cleaner way of handling these error messages.
*
* @return customized ErrorAttributes
*/
@Bean
public ErrorAttributes errorAttributes() {
return new DefaultErrorAttributes() {
@Override
public Map<String, Object> getErrorAttributes(
final RequestAttributes requestAttributes,
final boolean includeStackTrace) {
Map<String, Object> attributes = super
.getErrorAttributes(requestAttributes, includeStackTrace);
Throwable error = getError(requestAttributes);
if (error instanceof MethodArgumentNotValidException) {
MethodArgumentNotValidException ex =
((MethodArgumentNotValidException) error);
attributes.put("errors", ex.getMessage());
}
return attributes;
}
};
}
开发者ID:ssherwood,项目名称:spring-boot-jpa,代码行数:29,代码来源:BootJpaApplication.java
示例2: filterHasError
import org.springframework.boot.autoconfigure.web.DefaultErrorAttributes; //导入依赖的package包/类
@Test
public void filterHasError() {
this.filter.setErrorAttributes(new DefaultErrorAttributes());
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
MockHttpServletResponse response = new MockHttpServletResponse();
response.setStatus(500);
request.setAttribute("javax.servlet.error.exception",
new IllegalStateException("Foo"));
response.addHeader("Content-Type", "application/json");
Map<String, Object> trace = this.filter.getTrace(request);
this.filter.enhanceTrace(trace, response);
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) trace.get("error");
System.err.println(map);
assertThat(map.get("message").toString()).isEqualTo("Foo");
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:WebRequestTraceFilterTests.java
示例3: filterHasError
import org.springframework.boot.autoconfigure.web.DefaultErrorAttributes; //导入依赖的package包/类
@Test
public void filterHasError() {
this.filter.setErrorAttributes(new DefaultErrorAttributes());
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
MockHttpServletResponse response = new MockHttpServletResponse();
response.setStatus(500);
request.setAttribute("javax.servlet.error.exception",
new IllegalStateException("Foo"));
response.addHeader("Content-Type", "application/json");
Map<String, Object> trace = this.filter.getTrace(request);
this.filter.enhanceTrace(trace, response);
@SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) trace.get("error");
System.err.println(map);
assertEquals("Foo", map.get("message").toString());
}
开发者ID:Nephilim84,项目名称:contestparser,代码行数:17,代码来源:WebRequestTraceFilterTests.java
示例4: customizeErrorResponseAttributes
import org.springframework.boot.autoconfigure.web.DefaultErrorAttributes; //导入依赖的package包/类
@Bean
public ErrorAttributes customizeErrorResponseAttributes() {
return new DefaultErrorAttributes(){
@Override
public Map<String, Object> getErrorAttributes(RequestAttributes requestAttributes, boolean includeStackTrace) {
Map<String, Object> errorAttributes = super.getErrorAttributes(requestAttributes, includeStackTrace);
errorAttributes.remove("timestamp");
errorAttributes.remove("exception");
return errorAttributes;
}
};
}
开发者ID:quebic-source,项目名称:searchbox-core,代码行数:15,代码来源:SearchBoxConfiguration.java
示例5: ErrorController
import org.springframework.boot.autoconfigure.web.DefaultErrorAttributes; //导入依赖的package包/类
@Autowired
public ErrorController(ServerProperties serverProperties) {
super(new DefaultErrorAttributes(), serverProperties.getError());
}
开发者ID:lupindong,项目名称:xq_seckill_microservice,代码行数:5,代码来源:ErrorController.java
示例6: errorAttributes
import org.springframework.boot.autoconfigure.web.DefaultErrorAttributes; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public DefaultErrorAttributes errorAttributes() {
return new DefaultErrorAttributes();
}
开发者ID:Treydone,项目名称:mandrel,代码行数:6,代码来源:RestConfiguration.java
注:本文中的org.springframework.boot.autoconfigure.web.DefaultErrorAttributes类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论