类 AbstractErrorWebExceptionHandler
- java.lang.Object
- org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler
- 所有已实现的接口:
org.springframework.beans.factory.InitializingBean
,org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler
,org.springframework.web.server.WebExceptionHandler
public abstract class AbstractErrorWebExceptionHandler extends Object implements org.springframework.boot.web.reactive.error.ErrorWebExceptionHandler, org.springframework.beans.factory.InitializingBean
Abstract base class forErrorWebExceptionHandler
implementations.- 从以下版本开始:
- 2.0.0
- 另请参阅:
ErrorAttributes
构造器概要
构造器 构造器 说明 AbstractErrorWebExceptionHandler(org.springframework.boot.web.reactive.error.ErrorAttributes errorAttributes, ResourceProperties resourceProperties, org.springframework.context.ApplicationContext applicationContext)
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 void
afterPropertiesSet()
protected Throwable
getError(org.springframework.web.reactive.function.server.ServerRequest request)
Extract the original error from the current request.protected Map<String,Object>
getErrorAttributes(org.springframework.web.reactive.function.server.ServerRequest request, boolean includeStackTrace)
Extract the error attributes from the current request, to be used to populate error views or JSON payloads.protected abstract org.springframework.web.reactive.function.server.RouterFunction<org.springframework.web.reactive.function.server.ServerResponse>
getRoutingFunction(org.springframework.boot.web.reactive.error.ErrorAttributes errorAttributes)
Create aRouterFunction
that can route and handle errors as JSON responses or HTML views.reactor.core.publisher.Mono<Void>
handle(org.springframework.web.server.ServerWebExchange exchange, Throwable throwable)
protected boolean
isTraceEnabled(org.springframework.web.reactive.function.server.ServerRequest request)
Check whether the trace attribute has been set on the given request.protected reactor.core.publisher.Mono<org.springframework.web.reactive.function.server.ServerResponse>
renderDefaultErrorView(org.springframework.web.reactive.function.server.ServerResponse.BodyBuilder responseBody, Map<String,Object> error)
Render a default HTML "Whitelabel Error Page".protected reactor.core.publisher.Mono<org.springframework.web.reactive.function.server.ServerResponse>
renderErrorView(String viewName, org.springframework.web.reactive.function.server.ServerResponse.BodyBuilder responseBody, Map<String,Object> error)
Render the given error data as a view, using a template view if available or a static HTML file if available otherwise.void
setMessageReaders(List<org.springframework.http.codec.HttpMessageReader<?>> messageReaders)
Configure HTTP message readers to deserialize the request body with.void
setMessageWriters(List<org.springframework.http.codec.HttpMessageWriter<?>> messageWriters)
Configure HTTP message writers to serialize the response body with.void
setViewResolvers(List<org.springframework.web.reactive.result.view.ViewResolver> viewResolvers)
Configure theViewResolver
to use for rendering views.
构造器详细资料
AbstractErrorWebExceptionHandler
public AbstractErrorWebExceptionHandler(org.springframework.boot.web.reactive.error.ErrorAttributes errorAttributes, ResourceProperties resourceProperties, org.springframework.context.ApplicationContext applicationContext)
方法详细资料
setMessageWriters
public void setMessageWriters(List<org.springframework.http.codec.HttpMessageWriter<?>> messageWriters)
Configure HTTP message writers to serialize the response body with.- 参数:
messageWriters
- theHttpMessageWriter
s to use
setMessageReaders
public void setMessageReaders(List<org.springframework.http.codec.HttpMessageReader<?>> messageReaders)
Configure HTTP message readers to deserialize the request body with.- 参数:
messageReaders
- theHttpMessageReader
s to use
setViewResolvers
public void setViewResolvers(List<org.springframework.web.reactive.result.view.ViewResolver> viewResolvers)
Configure theViewResolver
to use for rendering views.- 参数:
viewResolvers
- the list ofViewResolver
s to use
getErrorAttributes
protected Map<String,Object> getErrorAttributes(org.springframework.web.reactive.function.server.ServerRequest request, boolean includeStackTrace)
Extract the error attributes from the current request, to be used to populate error views or JSON payloads.- 参数:
request
- the source requestincludeStackTrace
- whether to include the error stacktrace information- 返回:
- the error attributes as a Map.
getError
protected Throwable getError(org.springframework.web.reactive.function.server.ServerRequest request)
Extract the original error from the current request.- 参数:
request
- the source request- 返回:
- the error
isTraceEnabled
protected boolean isTraceEnabled(org.springframework.web.reactive.function.server.ServerRequest request)
Check whether the trace attribute has been set on the given request.- 参数:
request
- the source request- 返回:
true
if the error trace has been requested,false
otherwise
renderErrorView
protected reactor.core.publisher.Mono<org.springframework.web.reactive.function.server.ServerResponse> renderErrorView(String viewName, org.springframework.web.reactive.function.server.ServerResponse.BodyBuilder responseBody, Map<String,Object> error)
Render the given error data as a view, using a template view if available or a static HTML file if available otherwise. This will return an emptyPublisher
if none of the above are available.- 参数:
viewName
- the view nameresponseBody
- the error response being builterror
- the error data as a map- 返回:
- a Publisher of the
ServerResponse
renderDefaultErrorView
protected reactor.core.publisher.Mono<org.springframework.web.reactive.function.server.ServerResponse> renderDefaultErrorView(org.springframework.web.reactive.function.server.ServerResponse.BodyBuilder responseBody, Map<String,Object> error)
Render a default HTML "Whitelabel Error Page".Useful when no other error view is available in the application.
- 参数:
responseBody
- the error response being builterror
- the error data as a map- 返回:
- a Publisher of the
ServerResponse
afterPropertiesSet
public void afterPropertiesSet() throws Exception
- 指定者:
afterPropertiesSet
在接口中org.springframework.beans.factory.InitializingBean
- 抛出:
Exception
getRoutingFunction
protected abstract org.springframework.web.reactive.function.server.RouterFunction<org.springframework.web.reactive.function.server.ServerResponse> getRoutingFunction(org.springframework.boot.web.reactive.error.ErrorAttributes errorAttributes)
Create aRouterFunction
that can route and handle errors as JSON responses or HTML views.If the returned
RouterFunction
doesn't route to aHandlerFunction
, the original exception is propagated in the pipeline and can be processed by otherWebExceptionHandler
s.- 参数:
errorAttributes
- theErrorAttributes
instance to use to extract error information- 返回:
- a
RouterFunction
that routes and handles errors