I have been reading a lot and can't find a solution that tells me how to inlucde the maven profiles in @activeprofiles annotation . Is it possible or not?
The issue that I am trying to solve to get H2 and flyway start before my tests execute which is not happening. The configuration is decscribed in maven profiles in pom.xml. When the tests run in teamcity it picks the maven profile and execute but as standalone they can't find the configuration for H2 and flyway and fail on starting.
... can't find a solution that tells me how to inlucde the maven profiles in @activeprofiles annotation.
Do you mean to active Spring profiles based on maven profile, if so, you can configure it like so in your pom.xml:
<profiles>
<profile>
<id>mvnprofile</id>
<properties>
<spring.profiles.active>springprofile</spring.profiles.active>
</properties>
<dependencies>
<dependency>
</dependency>
</dependencies>
</profile>
...
</profiles>
In your test class configure the profiles it should run on ..
@Runwith(..)
@SpringApplicationConfiguration(...)
@ActiveProfiles("springprofile")
public class YourTest { ... }
For profile specific properties, create an application-springprofile.properties
in addition to your application.properties
, Spring Boot will first load application.properties then load application-springprofile.properties -- overriding any properties previously configured from application.properties.
Finally, you set the maven profile with -P flag
$mvn test -P mvnprofile
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With