๐๐ SPRING CERTIFICATION QUESTION:
Which is ๐๐๐ a valid way to activate the profiles: 'cloud', and 'jpa'?
๐๐ SPRING CERTIFICATION QUESTION:
Which is ๐๐๐ a valid way to activate the profiles: 'cloud', and 'jpa'?
* Using a system property via command-line:
* Using 'web.xml' 'spring-profiles' tag:
* Using a system property programmatically:
* Using @ActiveProfiles annotation (in integration tests only)
#spring #certificationquestion #vcp
Answer:
1) We can use:
JVM System Parameter
The profile names can also be passed in via a JVM system parameter. These profiles will be activated during application startup:
-Dspring.profiles.active=dev
2) We can set the system property:
System.setProperty("spring.profiles.active", "cloud,jpa");
SpringApplication.run(MyConfig.class);
3) We can use:
@ActiveProfile in Tests
Tests make it very easy to specify what profiles are active using the @ActiveProfile annotation to enable specific profiles:
@ActiveProfiles("dev")
So far, we've looked at multiple ways of activating profiles. Let's now see which one has priority over the other and what happens if we use more than one, from highest to lowest priority:
- Context parameter in web.xml
- WebApplicationInitializer
- JVM System parameter
- Environment variable
- Maven profile
4) We can use:
Similarly, we can define the active profiles in the web.xml file of the web application using a context parameter:
๐๐๐ <๐๐๐๐๐๐-๐๐๐๐๐๐๐๐> ๐๐๐๐๐๐๐ ๐ ๐๐๐ ๐๐๐ ๐๐๐๐๐ ๐๐ ๐๐๐ ๐๐๐.๐๐๐ ๐๐๐๐.