'How to run spring boot application with profile from commandline?
I am using spring boot and maven to have multiple environments for dev, unit test, integration test, stage, and prod environment.
Test: with @Profile
@SpringBootTest
@Profile("utest")
class DemoApplicationTests {
@Test
void contextLoads() {
}
}
I have tried with @ActiveProfiles too. It does not work.
@SpringBootTest
@ActiveProfiles("utest")
class DemoApplicationTests {
@Test
void contextLoads() {
}
}
Folder structure:
.
├── java
│ └── com
│ └── example
│ └── demo
│ └── DemoApplication.java
└── resources
├── application-utest.properties
├── application.properties
├── static
└── templates
I have created a new file application-utest.properties file.
application.properties
server.port=5001
application-utest.properties
server.port=6000
When I run:
mvn test -P utest
Getting this error:
[INFO]
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 2 resources
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.779 s
[INFO] Finished at: 2022-02-15T23:00:38+05:30
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "utest" could not be activated because it does not exist.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources) on project demo: Execution default-resources of goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources failed: newPosition < 0: (-1 < 0) -> [Help 1]
[ERROR]
This says the profile does not exist. How to use spring boot profiles the correct way?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
