Hello I have a maven spring boot rest project. I want to add dev and prod configurations to it but it is not working.
Under /src/main/resources i created application.yaml, application-dev.yaml and application-prod.yaml
# application.yaml
spring:
profiles:
active: prod
# application-dev.yaml
server:
port: 8080
spring:
datasource:
url: jdbc:h2:mem:mydb
username: sa
password: password
driverClassName: org.h2.Driver
# application-prod.yaml
server:
port: 8099
spring:
datasource:
url: jdbc:postgresql://localhost:5432/WsDb
username: postgres
password: postgres
driverClassName: org.postgresql.Driver
in pom.xml i have the following:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencies>
...
</dependencies>
<build>
<resources>
<resource>
<directory>/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>dev</id>
<properties>
<spring.profiles.active>dev</spring.profiles.active>
</properties>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
</dependencies>
</profile>
<profile>
<id>prod</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<spring.profiles.active>prod</spring.profiles.active>
</properties>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgres.version}</version>
</dependency>
</dependencies>
</profile>
</profiles>
when i run the application in Intellij Idea with debug configuration with the command mvn clean package spring-boot:run -Dspring.profiles.active = prod it says :
Test Phase output
The following 1 profile is active: "prod"
Bootstrapping Spring Data JPA repositories in DEFAULT mode.
Finished Spring Data repository scanning in 164 ms. Found 2 JPA repository interfaces.
Replacing 'dataSource' DataSource bean with embedded version
Starting embedded database: url='jdbc:h2:mem:4348112a-775e-4b78-a5b7-e5bcfdf21761
HHH000204: Processing PersistenceUnitInfo [name: default]
Run phase output
No active profile set, falling back to 1 default profile: "default"
Bootstrapping Spring Data JPA repositories in DEFAULT mode.
Finished Spring Data repository scanning in 116 ms. Found 2 JPA repository interfaces.
Tomcat initialized with port 8080 (http)
Starting service [Tomcat]



As far as I can see the command line argument
-Dspring.profiles.active=prodhas no affect. The spring-boot plugin documentation describes how to activate the profiles.In your project the
prodprofile is activated only because of the propertyspring.profiles.activein theapplication.yamlfile. That has lured me onto the wrong ferry.In the spring documentation there is also an example how to activate the spring profiles with maven profiles.