Error creating bean with name cassandrahealthcontributor defined in class path resource

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-05-10 23:00:10.030 ERROR 7765 --- [    Test worker] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'embeddedMongoServer' defined in class path resource [org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.class]: Unsatisfied dependency expressed through method 'embeddedMongoServer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedMongoConfiguration' defined in class path resource [org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [de.flapdoodle.embed.mongo.config.MongodConfig]: Factory method 'embeddedMongoConfiguration' threw exception; nested exception is java.lang.IllegalStateException: Set the spring.mongodb.embedded.version property or define your own MongodConfig bean to use embedded MongoDB

위와 같은 에러가 뜨는 경우 해결 방법

밑줄 친 부분을 보니 내장 mongoDB를 쓰고 싶으면 spring.mongodb.embedded.version에 대한 property를 설정해주라는 이야기인 듯 하다.

찾아보니 spring boot 2.6 이후부터 spring.mongodb.embedded.version은 자동 구성된 임베디드 MongoDB를 사용하도록 설정해야하는것 같다.

test 폴더의 하위에 recources 폴더를 만들고

application.yml 파일을 아래와 같이 생성한다.

// test/resources/application.yml spring: mongodb: embedded: version: 3.3.4
Error creating bean with name cassandrahealthcontributor defined in class path resource

문서의 내용을 보면 production에서 사용할 mongodb의 버전과 embedded.mongo의 버전을 동일하게 해주면 된다고 한다.

그래서 현재(2022.05.10) 기준 spring data mongo는 3.3.4 버전을 지원하기 때문에 embedded 버전도 3.3.4로 맞춰주었다.

Error creating bean with name cassandrahealthcontributor defined in class path resource
spring 공식문서

테스트 해보면 정상 동작할 것이다.

해결!

2022.05.10
springboot 2.6.7 기준
mongodb.embedded.version 으로 3.3.43.5.5, 3.6.5, latest 등이 사용 가능했다..

  • java.lang.Object
    • org.springframework.boot.actuate.autoconfigure.health.AbstractCompositeHealthContributorConfiguration<org.springframework.boot.actuate.health.HealthContributor,I,B>
      • org.springframework.boot.actuate.autoconfigure.health.CompositeHealthContributorConfiguration<org.springframework.boot.actuate.cassandra.CassandraHealthIndicator,org.springframework.data.cassandra.core.CassandraOperations>
        • org.springframework.boot.actuate.autoconfigure.cassandra.CassandraHealthContributorAutoConfiguration



  • @Configuration(proxyBeanMethods=false) @ConditionalOnClass(value={com.datastax.oss.driver.api.core.CqlSession.class,org.springframework.data.cassandra.core.CassandraOperations.class}) @ConditionalOnBean(value=org.springframework.data.cassandra.core.CassandraOperations.class) @ConditionalOnEnabledHealthIndicator(value="cassandra") @AutoConfigureAfter(value={org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration.class,org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration.class,CassandraReactiveHealthContributorAutoConfiguration.class}) public class CassandraHealthContributorAutoConfiguration extends CompositeHealthContributorConfiguration<org.springframework.boot.actuate.cassandra.CassandraHealthIndicator,org.springframework.data.cassandra.core.CassandraOperations>

    Auto-configuration for CassandraHealthIndicator.

    Since: 2.1.0

    • Constructor Summary

    • Method Summary

      • Methods inherited from class org.springframework.boot.actuate.autoconfigure.health.CompositeHealthContributorConfiguration

        createComposite
      • Methods inherited from class org.springframework.boot.actuate.autoconfigure.health.AbstractCompositeHealthContributorConfiguration

        createContributor, createIndicator
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    • Constructor Detail

      • CassandraHealthContributorAutoConfiguration

        public CassandraHealthContributorAutoConfiguration()
    • Method Detail

      • cassandraHealthContributor

        @Bean @ConditionalOnMissingBean(name={"cassandraHealthIndicator","cassandraHealthContributor"}) public org.springframework.boot.actuate.health.HealthContributor cassandraHealthContributor(java.util.Map<java.lang.String,org.springframework.data.cassandra.core.CassandraOperations> cassandraOperations)