Hello,
Overview of the problem:
While having in a project dependency to org.springframework.cloud:spring-cloud-starter-sleuth:3.1.9 and org.springframework.boot:spring-boot-docker-compose:3.1.2 with postgres in compose.yaml I'm getting org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'jdbcConnectionDetailsForApplicationServicePostgres1' defined in null: Cannot register bean definition [Root bean: class [org.springframework.boot.docker.compose.service.connection.postgres.PostgresJdbcDockerComposeConnectionDetailsFactory$PostgresJdbcDockerComposeConnectionDetails (...) exception
Detailed description
While starting the application (org.springframework.boot.SpringApplication#run(java.lang.String...)), among others, the following are called as described:
1. org.springframework.boot.SpringApplication#prepareContext which results in emitting org.springframework.boot.context.event.ApplicationPreparedEvent
2. org.springframework.boot.SpringApplication#refreshContext which results in emitting org.springframework.context.event.ContextRefreshedEvent
In the meantime, two things are happening:
* Docker compose:
* org.springframework.boot.docker.compose.lifecycle.DockerComposeListener reacts to ApplicationPreparedEvent and ensures that container is running and then it emits org.springframework.boot.docker.compose.lifecycle.DockerComposeServicesReadyEvent
* org.springframework.boot.docker.compose.service.connection.DockerComposeServiceConnectionsApplicationListener reacts to DockerComposeServicesReadyEvent and registers org.springframework.boot.autoconfigure.service.connection.ConnectionDetails for running service.
* Spring Cloud:
* org.springframework.cloud.context.restart.RestartListener reacts to ContextRefreshedEvent and emits ApplicationPreparedEvent
* DockerComposeListener kicks in for the second time and tries to register ConnectionDetails bean
Comment From: wilkinsona
Duplicates https://github.com/spring-cloud/spring-cloud-commons/issues/1248.