0

With IntelliJ, I can specify a Spring boot profile to run when starting a service enter image description here

However, if I run mvn clean install, then the tests are run with the default profile, which causes them to fail. How can I tell mvn to run the tests with a specific Spring Boot profile?

Peter Kronenberg
  • 878
  • 10
  • 32
  • https://stackoverflow.com/questions/42390860/configure-active-profile-in-springboot-via-maven – BarbetNL Jun 27 '22 at 20:51
  • @BarbetNL using Maven profiles is the wrong way. – khmarbaise Jun 27 '22 at 21:18
  • 1
    You have to define the profiles in your tests or even better use the appropriate `application.properteis` in `src/test/resources` for all tests or define them at the appropriate tests (https://docs.spring.io/spring-boot/docs/2.7.1/reference/htmlsingle/#features.profiles) – khmarbaise Jun 27 '22 at 21:21
  • There are some other suggestions in that link I posted. There are many ways to do this. Peter's question is how to do it in command-line: mvn spring-boot:run -Dspring.profiles.active={profile_name} – BarbetNL Jun 28 '22 at 07:39

1 Answers1

2

Create/define a properties file and put it within your src/test/resources folder.

Use class level annotation @ActiveProfiles and specify your property file name like this @ActiveProfiles("myProperties")

Hope this helps!

Harsh
  • 812
  • 1
  • 10
  • 23