Description
Issue Description:
When using Docker Compose in combination with Spring Boot and defining multiple services with profiles in the compose.yaml
file, there seems to be an issue with the Spring Boot behavior when specifying an active profile. Specifically, even if only one profile is specified, Spring Boot is considering all the services, leading to unexpected behavior.
Steps to Reproduce:
- Define multiple services with profiles in the
docker-compose.yaml
file.
version: "3"
services:
authorization_server:
profiles:
- server
platform: linux/amd64
image: mysql:8.0.23
container_name: server_database
---
----
client:
profiles:
- client
platform: linux/amd64
image: mysql:8.0.23
container_name: client_database
---
---
- Manually start all the services in the Docker Compose file.
- In the Spring Boot application, set
spring.docker.compose.profiles.active=server
(or any other specific profile). - Observe that Spring Boot is considering all the active services instead of just the one with the specified profile.
Expected Behavior:
When specifying an active profile, Spring Boot should only consider the services associated with that profile, and ignore the others.
Actual Behavior:
Spring Boot is considering all services, leading to conflicts, as illustrated by the following error message:
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 1 of method dataSource in org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari required a single bean, but 2 were found:
- jdbcConnectionDetailsForClient_database: defined in unknown location
- jdbcConnectionDetailsForServer_database: defined in unknown location
This may be due to missing parameter name information
Action:
Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed
Additional Information:
- Spring Boot version: 3.2.3
- Docker Compose version: v2.24.6-desktop.1
- Operating System: macOS Sonoma 14.2.1
Possible Solution:
Ensure that Spring Boot correctly filters and activates only the services associated with the specified active profile in Docker Compose.
Note:
This issue is causing inconvenience in managing profiles and services, and a resolution is highly appreciated.