Issue
I have a library JAR that taps into Spring Boot auto-configuration in order to register an interceptor for logging purposes.
My issue is that when I add the library as a dependency into a particular Spring Boot project, the interceptor is not registered. It works for all of our other Spring Boot projects.
None of my breakpoints in the library code are hit in debug mode.
The problem Spring Boot project does have @SpringBootApplication
and has Spring MVC via spring-boot-starter-web
.
This class extending WebMvcConfigurationSupport
seems to be preventing my interceptor from being registered:
@Configuration
public class JacksonHttpMessageConfig extends WebMvcConfigurationSupport
{
@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
ObjectMapper om = new ObjectMapper();
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
om.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
jsonConverter.setObjectMapper(om);
return jsonConverter;
}
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(mappingJackson2HttpMessageConverter());
super.addDefaultHttpMessageConverters(converters);
}
}
When I delete this class, the interceptor is registered successfully.
Why is this happening and what are the approaches to fix it?
Solution
I found that the issue was that Spring Boot disables auto-configuration for MVC components when it sees a @Configuration
class that extends WebMvcConfigurationSupport
.
The solution was to have the class not extend WebMvcConfigurationSupport
.
Answered By - kernelpanic
Answer Checked By - Willingham (JavaFixing Volunteer)