我解决了我的问题。这里配置类
package config;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication
import org.springframework.boot.web.embedded.netty.NettyServerCustomizer
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.zalando.logbook.Logbook
import org.zalando.logbook.netty.LogbookServerHandler
import reactor.netty.Connection
import reactor.netty.http.server.HttpServer
import reactor.netty.tcp.TcpServer
@Configuration(proxyBeanMethods = false)
class LogbookFluxConfig {
companion object {
const val CUSTOMIZER_NAME = "logbookNettyServerCustomizer"
}
@Bean
@ConditionalOnProperty(name = ["logbook.filter.enabled"], havingValue = "true", matchIfMissing = true)
@ConditionalOnMissingBean(name = [CUSTOMIZER_NAME])
@ConditionalOnClass(HttpServer::class)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
fun logbookNettyServerCustomizer(logbook: Logbook?): NettyServerCustomizer {
return NettyServerCustomizer { httpServer: HttpServer ->
httpServer.tcpConfiguration { tcpServer: TcpServer ->
tcpServer.doOnConnection { connection: Connection ->
connection.addHandlerLast(LogbookServerHandler(logbook!!))
}
}
}
}
}
应用程序.yml
logging:
level:
org:
zalando:
logbook: TRACE
logbook:
include: /api/**
filter.enabled: ${LOGBOOK_FILTER_ENABLED:true}
format.style: http
obfuscate.write.category: http.wire-log
write:
chunk-size: ${LOGBOOK_CHUNK_SIZE:1000}
max-body-size: ${LOGBOOK_WRITE_MAX_BODY_SIZE:100000}
level: ${LOGBOOK_WRITE_LEVEL:INFO}
和依赖项(部分)
implementation("org.zalando:logbook-spring-boot-autoconfigure:2.5.0") {
exclude(group = "javax.servlet", module = "javax.servlet-api")
}
implementation("org.zalando:logbook-netty:2.5.0")
现在我可以继续使用旧版本的 spring boot
plugins {
id("org.springframework.boot") version "2.2.4.RELEASE"
id("io.spring.dependency-management") version "1.0.9.RELEASE"
}