Skip to content

LogbookAutoConfiguration fails in environments without Spring Web (missing ClientHttpRequestInterceptor) #2174

@clinmanc

Description

@clinmanc

Description

When using logbook-spring-boot-starter in a project that does not include spring-web, the LogbookAutoConfiguration unconditionally registers a LogbookClientHttpRequestInterceptor bean.
This causes a ClassNotFoundException since org.springframework.http.client.ClientHttpRequestInterceptor is not present.

Expected Behavior

LogbookAutoConfiguration should not fail in environments without Spring Web.
The LogbookClientHttpRequestInterceptor bean should only be created if ClientHttpRequestInterceptor is available on the classpath.

Actual Behavior

Application startup fails with the following error:

Caused by: java.lang.ClassNotFoundException: org.springframework.http.client.ClientHttpRequestInterceptor

Possible Fix

Update LogbookAutoConfiguration to conditionally register the bean, for example:

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({
        ClientHttpRequestInterceptor.class,
        LogbookClientHttpRequestInterceptor.class
})
static class ClientHttpAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean(LogbookClientHttpRequestInterceptor.class)
    public LogbookClientHttpRequestInterceptor logbookClientHttpRequestInterceptor(Logbook logbook) {
        return new LogbookClientHttpRequestInterceptor(logbook);
    }

}

Steps to Reproduce

Create a new Spring Boot project without including spring-boot-starter-web.

Add logbook-spring-boot-starter as a dependency.

Start the application.

Observe the ClassNotFoundException.

Context

We are using Logbook in a non-web Spring Boot application (for logging outgoing requests/responses from other HTTP clients, not via Spring Web).
The unconditional creation of the Spring-specific interceptor prevents the application from starting.

Your Environment

Logbook version: 3.12.3

Spring Boot version: 3.5.5

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions