How can I control a bean's creation depending on whether there's not another, different bean in the project annotated with @EnableWebMvc?
I tried
@ConditionalOnMissingBean(WebMvcConfigurationSupport.class)
as suggested here but no luck. i get this contradicting state when @EnableWebMvc is there
WebMvcAutoConfiguration: Did not match: - @ConditionalOnMissingBean (types: org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; SearchStrategy: all) found beans of type 'org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport' org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration (OnBeanCondition)
and also
ProblemModulesRegisterer matched: - @ConditionalOnMissingBean (types: org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; SearchStrategy: all) did not find any beans (OnBeanCondition)
So it found and not found beans of type WebMvcConfigurationSupport
As another attempt, I also compared the registered beans with and without @EnableWebMvc and noticed that without it, there's a bean called org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration. So I tried a @ConditionalOnMissingBean(WebMvcAutoConfiguration.class) but it still doesn't work. It shows this contradicting state
WebMvcAutoConfiguration matched: - @ConditionalOnClass found required classes 'javax.servlet.Servlet', 'org.springframework.web.servlet.DispatcherServlet', 'org.springframework.web.servlet.config.annotation.WebMvcConfigurer' (OnClassCondition) - found 'session' scope (OnWebApplicationCondition) - @ConditionalOnMissingBean (types: org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; SearchStrategy: all) did not find any beans (OnBeanCondition)
and also
ProblemModulesRegisterer matched: - @ConditionalOnMissingBean (types: org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration; SearchStrategy: all) did not find any beans (OnBeanCondition)
So WebMvcAutoConfiguration matched (was created) and a dependency of missing WebMvcAutoConfiguration also matched