为什么SpringWebFlux在默认配置下没有异常堆栈跟踪? 问题:

为什么SpringWebFlux在默认配置下没有异常堆栈跟踪? 问题:,spring,spring-boot,netty,spring-webflux,project-reactor,Spring,Spring Boot,Netty,Spring Webflux,Project Reactor,我构建了一个服务器,并向我的路由器添加了以下代码:route(GET(“/test/{Id}”)、request->throw new RuntimeException(“123”) 但是当我调用/test/{Id}时,控制台中唯一的错误日志是: TRACE 153036 --- [ctor-http-nio-7] o.s.w.r.function.server.RouterFunctions : [fc7e809d] Matched org.springframework.web.react

我构建了一个服务器,并向我的路由器添加了以下代码:
route(GET(“/test/{Id}”)、request->throw new RuntimeException(“123”)

但是当我调用
/test/{Id}
时,控制台中唯一的错误日志是:

TRACE 153036 --- [ctor-http-nio-7] o.s.w.r.function.server.RouterFunctions  : [fc7e809d] Matched org.springframework.web.reactive.function.server.RequestPredicates$$Lambda$827/1369035321@9d8c274
DEBUG 153036 --- [ctor-http-nio-7] org.springframework.web.HttpLogging      : [fc7e809d] Resolved [RuntimeException: 123] for HTTP GET /test/job
TRACE 153036 --- [ctor-http-nio-7] org.springframework.web.HttpLogging      : [fc7e809d] Encoding [{timestamp=Mon Dec 17 15:34:43 CST 2018, path=/test/123, status=500, error=Internal Server Error, message=123}]
TRACE 153036 --- [ctor-http-nio-7] o.s.w.s.adapter.HttpWebHandlerAdapter    : [fc7e809d] Completed 500 INTERNAL_SERVER_ERROR, headers={masked}
TRACE 153036 --- [ctor-http-nio-7] org.springframework.web.HttpLogging      : [fc7e809d] Handling completed
没有堆栈跟踪,但为什么?应该由spring或netty处理,而不是我的自定义代码,对吗?设置
logging.level.org.springframework.web:trace
不是解决方案,日志太多了

以下是我到目前为止发现的,但仍然很困惑: 我已经检查了为什么SpringMVC有堆栈跟踪,因为tomcat中有一个堆栈跟踪,并且调试证明了这一点

然后我想纳蒂也有这些逻辑吗?事实上是这样!但让我困惑的是,我不能在这个带有断点的try-catch中暂停代码


这意味着可能存在一些
Mono.onErrorResume
吞咽异常,因此netty无法捕获任何内容。但我不知道如何调试大型Mono来检查根本原因。为什么要吞下它?

选项1A:按如下方式设置应用程序属性:

server.error.includeStacktrace=ALWAYS
server.error.includeStacktrace=ON_TRACE_PARAM
选项1B:按如下方式设置应用程序属性:

server.error.includeStacktrace=ALWAYS
server.error.includeStacktrace=ON_TRACE_PARAM
,指定请求参数
跟踪

选项2:添加自定义WebExceptionHandler,并确保它位于组件扫描范围内

@Component
@Order(-2)
public class LoggingErrorWebExceptionHandler extends DefaultErrorWebExceptionHandler {
    private static final Logger logger = LoggerFactory.getLogger(LoggingErrorWebExceptionHandler.class);

    public LoggingErrorWebExceptionHandler(ErrorAttributes errorAttributes, ResourceProperties resourceProperties,
            ServerProperties serverProperties, ApplicationContext applicationContext, ServerCodecConfigurer serverCodecConfigurer) {
        super(errorAttributes, resourceProperties, serverProperties.getError(), applicationContext);
        super.setMessageWriters(serverCodecConfigurer.getWriters());
        super.setMessageReaders(serverCodecConfigurer.getReaders());
    }

    @Override
    protected void logError(ServerRequest request, HttpStatus errorStatus) {
        Throwable ex = getError(request);
        logger.error("Error Occurred:", ex);
        super.logError(request, errorStatus);
    }

}

有关更多详细信息,请参阅。

第二个是解决方法,如果没有其他解决方案,我们必须使用此
CustomizedExceptionHandler
Hi,@ToffeeLu,您可以:
.doError(RuntimeException.class,e->logger.error(e))