Bird
Raised Fist0
Spring Bootframework~20 mins

Profile-based configuration in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Profile Configuration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
Spring Boot Profile Activation Behavior
Given a Spring Boot application with application.properties and application-dev.properties files, and the active profile set to dev, what will be the value of the property app.message if application.properties has app.message=Hello from default and application-dev.properties has app.message=Hello from dev?
AHello from default
BAn error occurs because of conflicting properties
CHello from dev
DThe property <code>app.message</code> will be empty
Attempts:
2 left
💡 Hint
Spring Boot uses the active profile properties to override default properties.
📝 Syntax
intermediate
2:00remaining
Correct Syntax for Profile-Specific Bean Declaration
Which of the following is the correct way to declare a Spring bean that only loads when the test profile is active?
A
@Bean
@Profile({test})
public DataSource testDataSource() { return new DataSource(); }
B
@Bean
@Profile(test)
public DataSource testDataSource() { return new DataSource(); }
C
@Bean
@Profile('test')
public DataSource testDataSource() { return new DataSource(); }
D
@Bean
@Profile("test")
public DataSource testDataSource() { return new DataSource(); }
Attempts:
2 left
💡 Hint
Profile annotation requires a string value with double quotes.
🔧 Debug
advanced
2:00remaining
Why Does the Profile-Specific Property Not Load?
A developer has application.properties and application-prod.properties. They set spring.profiles.active=prod in application.properties. But the properties from application-prod.properties are not loaded at runtime. What is the most likely cause?
AThe <code>spring.profiles.active</code> property must be set as a command-line argument or environment variable, not inside <code>application.properties</code>.
BSpring Boot does not support multiple property files for profiles.
CThe profile name <code>prod</code> is misspelled in the filename.
DSetting <code>spring.profiles.active</code> inside <code>application.properties</code> disables profile-specific loading.
Attempts:
2 left
💡 Hint
Active profiles set inside application.properties can cause loading order issues.
❓ state_output
advanced
2:00remaining
Output of Bean Initialization with Multiple Active Profiles
Consider a Spring Boot app with two active profiles: dev and qa. There are two beans defined with @Profile("dev") and @Profile("qa") respectively. What happens when the app starts?
AOnly the bean with <code>@Profile("dev")</code> loads because it is first in the list.
BBoth beans load because both profiles are active.
CNeither bean loads because Spring Boot supports only one active profile at a time.
DAn error occurs due to conflicting beans with different profiles.
Attempts:
2 left
💡 Hint
Spring Boot supports multiple active profiles simultaneously.
🧠 Conceptual
expert
3:00remaining
Understanding Profile-Specific Property Precedence
In Spring Boot, if you have application.properties, application-dev.properties, and application-local.properties, and you activate both dev and local profiles, which property file has the highest precedence when properties conflict?
AThe last profile listed in <code>spring.profiles.active</code> has the highest precedence
B<code>application-dev.properties</code> because it is the first profile alphabetically
C<code>application.properties</code> because it is the base configuration
D<code>application-local.properties</code> because it is loaded last
Attempts:
2 left
💡 Hint
Order of profiles in spring.profiles.active affects property overriding.

Practice

(1/5)
1. What is the main purpose of using profiles in Spring Boot configuration?
easy
A. To switch application settings easily for different environments
B. To write Java code faster
C. To create user interfaces
D. To manage database connections manually

Solution

  1. Step 1: Understand what profiles do

    Profiles allow you to have different settings for different environments like development, testing, and production.
  2. Step 2: Identify the main use

    Switching settings easily means you can run the same app with different configurations without changing code.
  3. Final Answer:

    To switch application settings easily for different environments -> Option A
  4. Quick Check:

    Profiles = environment-specific settings [OK]
Hint: Profiles = different settings for different environments [OK]
Common Mistakes:
  • Thinking profiles are for writing code
  • Confusing profiles with UI design
  • Believing profiles manage database manually
2. Which of the following is the correct way to name a Spring Boot properties file for a profile named dev?
easy
A. application-dev.properties
B. application.properties-dev
C. dev-application.properties
D. application_dev.properties

Solution

  1. Step 1: Recall Spring Boot profile file naming

    Spring Boot expects profile-specific files named as application-{profile}.properties.
  2. Step 2: Match the correct pattern

    For profile 'dev', the file should be application-dev.properties.
  3. Final Answer:

    application-dev.properties -> Option A
  4. Quick Check:

    Profile file = application-{profile}.properties [OK]
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

  1. Step 1: Understand profile override behavior

    Properties in profile-specific files override those in the default application.properties when the profile is active.
  2. Step 2: Apply active profile 'prod'

    Since 'prod' is active, server.port=9090 from application-prod.properties overrides 8080.
  3. Final Answer:

    9090 -> Option B
  4. 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

  1. Step 1: Check profile file naming

    Spring Boot requires profile files named with dash, not underscore.
  2. Step 2: Identify mismatch

    If the file is named application_dev.properties, Spring Boot won't recognize it for profile 'dev'.
  3. Final Answer:

    Incorrect profile file naming with underscore -> Option C
  4. 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

  1. Step 1: Recall command line profile activation syntax

    Spring Boot uses --spring.profiles.active=profile to activate profiles via command line arguments.
  2. 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.
  3. Final Answer:

    java -jar app.jar --spring.profiles.active=test -> Option D
  4. 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 unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard