'Injection problem in Spring Boot Test: "messageConverters must not be empty"

I have a strange problem with a Spring Boot Test. The test itself is empty, but it does not even manage to start the application. I get an error "Failed to load ApplicationContext", which is ultimately caused by an IllegalArgumentException: "'messageConverters' must not be empty".

java.lang.IllegalStateException: Failed to load ApplicationContext
        at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132)
        at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:124)
...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'messageConverters' must not be empty
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1804)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620)
...
Caused by: java.lang.IllegalArgumentException: 'messageConverters' must not be empty
        at org.springframework.util.Assert.notEmpty(Assert.java:470)
        at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.<init>(AbstractMessageConverterMethodArgumentResolver.java:98)
...

I have been able to track down this problem as only happening when I combine spring-boot-starter-data-cassandra and Keycloak (keycloak-spring-boot-starter). A test project can be found at https://www.dropbox.com/s/hs9b0ltxnd5lodg/demo.zip?dl=0

Please note that this is a stripped down version of my real application. I already found out that I can avoid the problem by removing the "@ComponentScan" annotation from my main class; however, in the real application, this is not possible for various reasons.

Can anybody explain the root cause of the problem and how to fix it?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source