Return to site

๐Ÿƒ๐ŸŽ“ SPRING CERTIFICATION QUESTION:

Which is ๐๐Ž๐“ a valid way to activate the profiles: 'cloud', and 'jpa'?

ยท vcp,spring,java

* 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:

๐’ƒ๐’–๐’• <๐’”๐’‘๐’“๐’Š๐’๐’ˆ-๐’‘๐’“๐’๐’‡๐’Š๐’๐’†๐’”> ๐’†๐’๐’†๐’Ž๐’†๐’๐’• ๐’…๐’๐’†๐’” ๐’๐’๐’• ๐’†๐’™๐’Š๐’”๐’• ๐’Š๐’ ๐’•๐’‰๐’† ๐’˜๐’†๐’ƒ.๐’™๐’Ž๐’ ๐’‡๐’Š๐’๐’†.