I have been using Spring Boot and TestNG for my test framework and so far my tests were configured to use only one default application.properties file which is under src/main/resource. Now I want to configure them for different environments - ci/stage etc. I have used spring documentation to activate the profiles from pom.xml file.
<profiles>
<profile>
<id>ci</id>
<properties>
<activeProfile>ci</activeProfile>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
I have for two properties files under src/main/resources - application.properties and application-ci.properties. (The is the naming convention suggested by spring documentation. application-{activatedprofile}.properties).
The application.properties have got a placeholder -
spring.profiles.active=@activeProfile@
The @activeProfile@ will get replaced with the value of activeProfile in the pom.xml file.And uptil that it is working.
In my @Configuration class I have a annotation as below and I am expecting that the ${spring.profiles.active} value gets replaced with value - ci.
@PropertySource("classpath:application-${spring.profiles.active}.properties")
I am getting following error:
java.lang.IllegalArgumentException: Could not resolve placeholder
'spring.profiles.active' in value
"classpath:application-${spring.profiles.active}.properties"
I am using maven and testng to run my project. I am doing something incorrect let me know how can I resolve it.
@activeProfile@replaced for tests in your code? actually for tests you could use@ActiveProfiles("ci")together with@SpringBootTest- Vasyl Sarzhynskyi@PropertySourceyou are also trying to outsmart Spring Boot (which already does all that for you, so you don't need it). Just pass the profile you want you use during startup of your application (or through an environment variable or simply by@ActiveProfileson your test classes. - M. Deinum