Error creating bean with name embeddedMongoServer defined in class path resource

I tried to upgrade my data-mongo example project to Spring Boot 2.6.0. There is a test designed to run against Testcontainers, I also included the embedded mongo dep for other tests, so I have to exclude the AutoConfiguration for embedded mongo to make sure this test working on Docker/testcontainers.

The following configuration worked well with Spring Boot 2.5.6.



@DataMongoTest
@ContextConfiguration(initializers = {MongodbContainerInitializer.class})
@EnableAutoConfiguration(exclude = EmbeddedMongoAutoConfiguration.class)
@Slf4j
@ActiveProfiles("test")
public class PostRepositoryTest {}

But after upgrading to Spring Boot 2.6.0 and running the application, I got the exception like this.


[ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: o
rg.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'embeddedMongoServer' defined in class path resource [org/springframework/boot/autoconfig
ure/mongo/embedded/EmbeddedMongoAutoConfiguration.class]: Unsatisfied dependency expressed through method 'embeddedMongoServer' parameter 0; nested exception is org.springframework.bea
ns.factory.BeanCreationException: Error creating bean with name 'embeddedMongoConfiguration' defined in class path resource [org/springframework/boot/autoconfigure/mongo/embedded/Embed
dedMongoAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [de.flap
doodle.embed.mongo.config.MongodConfig]: Factory method 'embeddedMongoConfiguration' threw exception; nested exception is java.lang.IllegalStateException: Set the spring.mongodb.embedd
ed.version property or define your own MongodConfig bean to use embedded MongoDB

Obviously, @EnableAutoConfiguration(exclude =...) did not affect the context in tests when upgrading to Spring Boot 2.6.0.

Update: Temporarily resolved it, see my answer below.


내가 노력으로 업그레이드 데이터-몽고 예제 프로젝트 봄 부팅 2.6.0. 가 테스트는 설계를 실행에 대한 Testcontainers,나도 포함되어 있는 임베디드 몽고 dep 다른 테스트,그래서 나이를 제외한 자동 구성 포함된 몽고 확인 이 테스트 작업에 도커/testcontainers.

다음과 같은 구성 및 일 봄 부팅 2.5.6.

@DataMongoTest @ContextConfiguration(initializers = {MongodbContainerInitializer.class}) @EnableAutoConfiguration(exclude = EmbeddedMongoAutoConfiguration.class) @Slf4j @ActiveProfiles("test") public class PostRepositoryTest {}

하지만 후 업그레이드 봄 부팅 2.6.0 고 응용 프로그램을 실행하고,나는 예외가 이와 같습니다.

[ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: o rg.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'embeddedMongoServer' defined in class path resource [org/springframework/boot/autoconfig ure/mongo/embedded/EmbeddedMongoAutoConfiguration.class]: Unsatisfied dependency expressed through method 'embeddedMongoServer' parameter 0; nested exception is org.springframework.bea ns.factory.BeanCreationException: Error creating bean with name 'embeddedMongoConfiguration' defined in class path resource [org/springframework/boot/autoconfigure/mongo/embedded/Embed dedMongoAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [de.flap doodle.embed.mongo.config.MongodConfig]: Factory method 'embeddedMongoConfiguration' threw exception; nested exception is java.lang.IllegalStateException: Set the spring.mongodb.embedd ed.version property or define your own MongodConfig bean to use embedded MongoDB

분명히, @EnableAutoConfiguration(exclude =...) 에 영향을 미치지 않았 컨텍스트에서 테스트를 업그레이드 할 때 봄 부팅 2.6.0.

업데이트:일시적으로 해결이 그것을 참조하십시오 나오.

Questions : Integration Test fails in jenkins with embedded mongodb

2022-08-02T05:16:27+00:00 2022-08-02T05:16:27+00:00

681

I ran my integration test locally, this anycodings_mongodb works fine. But when try running jenkins, it anycodings_mongodb fails. This integration test contain anycodings_mongodb embedded mongodb. The integration test is anycodings_mongodb below:

@RunWith(SpringRunner.class) @SpringBootTest @EnableAutoConfiguration public class MongoDbSpringUnitTest { @Autowired PriceRepository priceRepository; @Test public void testSavePriceMongoRepo() { priceRepository.deleteAll(); Price price = priceRepository.save(new Price("1234productId", 24.5f)); // System.out.println("id : "+price); assertEquals(0,24.5f, price.getCost()); assertNotNull("id is autogenerate", price.getId()); }

getting below error:

java.lang.IllegalStateException: Failed to load ApplicationContext Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'priceController': Unsatisfied dependency expressed through field 'priceRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'priceRepository': Cannot resolve reference to bean 'mongoTemplate' while setting bean property 'mongoOperations'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mongoTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'mongoTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoDbFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.MongoDbFactorySupport]: Factory method 'mongoDbFactory' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedMongoServer' 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.MongodExecutable]: Factory method 'embeddedMongoServer' threw exception; nested exception is java.lang.IllegalArgumentException: this version does not support 32Bit: Version{3.5.5}:Windows:B32

above error show that embebbed db server anycodings_mongodb cannot installed on 32 bit machine. I am not anycodings_mongodb sure jenkins only support 32-bits. I am anycodings_mongodb using jenkins 2.164.2.

The full code is present in below anycodings_mongodb github: https://github.com/ranjit5311/MicroServiceCode

Please let me know to resolve this issue.

Thanks, Ranjit Kumar

Total Answers 1

25

Answers 1 : of Integration Test fails in jenkins with embedded mongodb

After installing new version of Jenkins anycodings_jenkins 2.164.3, resolved this issue.

0

2022-08-02T05:16:27+00:00 2022-08-02T05:16:27+00:00Answer Link

mRahman