0

I have some issues with my custom autoconfiguration output and I am trying to figure out what is the problem by reading debug=true output of SpringBoot startup one of a beans that I am interested in is com.fasterxml.jackson.databind.ObjectMapper. I can confirm that it is created during the startup

   JacksonAutoConfiguration matched:
      - @ConditionalOnClass found required class 'com.fasterxml.jackson.databind.ObjectMapper' (OnClassCondition)

   JacksonAutoConfiguration.Jackson2ObjectMapperBuilderCustomizerConfiguration matched:
      - @ConditionalOnClass found required class 'org.springframework.http.converter.json.Jackson2ObjectMapperBuilder' (OnClassCondition)

   JacksonAutoConfiguration.JacksonObjectMapperBuilderConfiguration matched:
      - @ConditionalOnClass found required class 'org.springframework.http.converter.json.Jackson2ObjectMapperBuilder' (OnClassCondition)

   JacksonAutoConfiguration.JacksonObjectMapperBuilderConfiguration#jacksonObjectMapperBuilder matched:
      - @ConditionalOnMissingBean (types: org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; SearchStrategy: all) did not find any beans (OnBeanCondition)

   JacksonAutoConfiguration.JacksonObjectMapperConfiguration matched:
      - @ConditionalOnClass found required class 'org.springframework.http.converter.json.Jackson2ObjectMapperBuilder' (OnClassCondition)

/////////////////////// IT IS HERE!
   JacksonAutoConfiguration.JacksonObjectMapperConfiguration#jacksonObjectMapper matched:
      - @ConditionalOnMissingBean (types: com.fasterxml.jackson.databind.ObjectMapper; SearchStrategy: all) did not find any beans (OnBeanCondition)

However, after checking the implementation of JacksonAutoConfiguration I have noticed that this particular bean is not a public one

@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(ObjectMapper.class)
public class JacksonAutoConfiguration {

......

    @Configuration(proxyBeanMethods = false)
    @ConditionalOnClass(Jackson2ObjectMapperBuilder.class)
    static class JacksonObjectMapperConfiguration {

        @Bean
        @Primary
        @ConditionalOnMissingBean
        ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
            return builder.createXmlMapper(false).build();
        }

    }
}

so both config class and bean method are not public.

Now the question is, is such @Bean globally injectable? If not, how to distinguish such "hidden" beans from public ones in debug output?

The question originates from the fact that in my case, one of my autoconfiguration fails to boot due to failing @ConditionalOnBean(ObjectMapper.class}) condition check which would suggest that is is indeed an visibility issue (or maybe just bean naming?)

Why @ConditionalOnBean does not match despite fullfilled criteria?

Antoniossss
  • 31,590
  • 6
  • 57
  • 99
  • There are no hidden beans and the method qualifier doesn't impact the visibility/usability of beans. You are seeking in the wrong way. – M. Deinum Jun 12 '23 at 07:27
  • Yeah, this is what internet says (altough there was such functionality somewhere in spring 1). Any idea why this can happen or where/how to look for the issue? – Antoniossss Jun 12 '23 at 07:29
  • There has **never** been such functionality in Spring (and not at all in Spring 1). There has been experimental support in the Spring Java Config project, the predecessor of the java config now available in Spring. But that support has been dropped as it was too complex, too experimental and let to too much surprises. – M. Deinum Jun 12 '23 at 07:31
  • https://docs.spring.io/spring-javaconfig/docs/1.0-m2a/reference/html/bean-visibility.html that is for spring javaconfig indeed. – Antoniossss Jun 12 '23 at 08:13

0 Answers0