本文整理汇总了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;
}
};
}
示例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());
}
示例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;
}
};
}
示例5: ErrorController
import org.springframework.boot.autoconfigure.web.DefaultErrorAttributes; //导入依赖的package包/类
@Autowired
public ErrorController(ServerProperties serverProperties) {
super(new DefaultErrorAttributes(), serverProperties.getError());
}
示例6: errorAttributes
import org.springframework.boot.autoconfigure.web.DefaultErrorAttributes; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public DefaultErrorAttributes errorAttributes() {
return new DefaultErrorAttributes();
}