What is profile-based configuration in Spring Boot?
It is a way to define different settings for different environments (like development, testing, production) so the app behaves correctly in each.
Click to reveal answer
beginner
How do you activate a Spring Boot profile?
You can activate a profile by setting the property spring.profiles.active in application.properties or by passing --spring.profiles.active=profileName as a command line argument.
Click to reveal answer
beginner
What file naming convention does Spring Boot use for profile-specific properties?
Spring Boot uses application-{profile}.properties or application-{profile}.yml where {profile} is the profile name, like application-dev.properties.
Click to reveal answer
intermediate
Can multiple profiles be active at the same time in Spring Boot?
Yes, you can activate multiple profiles by separating them with commas, like spring.profiles.active=dev,debug. Settings from all active profiles are combined.
Click to reveal answer
beginner
Why is profile-based configuration useful in real projects?
It helps keep environment-specific settings separate, so you don’t mix development settings with production ones. This reduces errors and makes deployment safer.
Click to reveal answer
Which file would Spring Boot load if the active profile is 'test'?
Aapplication-test.properties
Bapplication.properties
Capplication-prod.properties
Dapplication-default.properties
✗ Incorrect
Spring Boot loads the profile-specific file named with the active profile, like application-test.properties.
How do you specify the active profile when running a Spring Boot app from the command line?
A--spring.profiles.active=profileName
B--profile=profileName
Cspring.active=profileName
Dprofile.active=profileName
✗ Incorrect
The correct syntax is --spring.profiles.active=profileName to activate a profile.
If no profile is active, which configuration file does Spring Boot use?
ANo configuration file is loaded
Bapplication-default.properties
Capplication-prod.properties
Dapplication.properties
✗ Incorrect
Spring Boot uses application.properties as the default configuration file when no profile is active.
Can you combine settings from multiple active profiles?
ANo, profiles override each other completely
BYes, Spring Boot merges settings from all active profiles
CYes, but only the first profile’s settings are used
DNo, only one profile can be active at a time
✗ Incorrect
Spring Boot merges settings from all active profiles, allowing combined configuration.
What is the main benefit of using profile-based configuration?
Hint: Profile files use dash between application and profile [OK]
Common Mistakes:
Using underscore instead of dash
Placing profile after .properties
Starting filename with profile name
3. Given these files: application.properties contains server.port=8080 application-prod.properties contains server.port=9090 And the active profile is set to prod, what port will the Spring Boot app run on?
medium
A. 8080
B. 9090
C. Both 8080 and 9090
D. No port will be set
Solution
Step 1: Understand profile override behavior
Properties in profile-specific files override those in the default application.properties when the profile is active.
Step 2: Apply active profile 'prod'
Since 'prod' is active, server.port=9090 from application-prod.properties overrides 8080.
Final Answer:
9090 -> Option B
Quick Check:
Active profile properties override default [OK]
Hint: Active profile settings override defaults [OK]
Common Mistakes:
Assuming default always applies
Thinking both ports run simultaneously
Ignoring profile activation
4. You wrote spring.profiles.active=dev in application.properties, but your app still uses default settings. What is the likely problem?
medium
A. The dev profile is not supported by Spring Boot
B. You need to restart the app after changing profiles
C. The profile-specific file is named application_dev.properties instead of application-dev.properties
D. Profiles cannot be set in application.properties
Solution
Step 1: Check profile file naming
Spring Boot requires profile files named with dash, not underscore.
Step 2: Identify mismatch
If the file is named application_dev.properties, Spring Boot won't recognize it for profile 'dev'.
Final Answer:
Incorrect profile file naming with underscore -> Option C
Quick Check:
Profile file must use dash, not underscore [OK]
Hint: Use dash, not underscore, in profile filenames [OK]
Common Mistakes:
Thinking profiles can't be set in application.properties
Forgetting to restart app (usually needed but not main issue here)
Believing 'dev' profile is unsupported
5. You want to activate the test profile without changing application.properties. Which of these is a valid way to do it when running your Spring Boot app from the command line?
hard
A. java -jar app.jar -profile test
B. java -jar app.jar -Dspring.profiles.active=test
C. java -jar app.jar --profile=test
D. java -jar app.jar --spring.profiles.active=test
Solution
Step 1: Recall command line profile activation syntax
Spring Boot uses --spring.profiles.active=profile to activate profiles via command line arguments.
Step 2: Check each option
java -jar app.jar --spring.profiles.active=test uses the correct Spring Boot command-line syntax. java -jar app.jar -Dspring.profiles.active=test incorrectly places the -D JVM argument after -jar; correct would be java -Dspring.profiles.active=test -jar app.jar. Flags like -profile test and --profile=test are not supported by Spring Boot.
Final Answer:
java -jar app.jar --spring.profiles.active=test -> Option D
Quick Check:
Use --spring.profiles.active=profile on command line [OK]
Hint: Use --spring.profiles.active=profile to activate profiles [OK]
Common Mistakes:
Using -profile or --profile flags incorrectly
Confusing JVM -D options without proper placement
Trying to set profile inside application.properties only
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.