Bird
Raised Fist0
Spring Bootframework~20 mins

Test profiles and configuration in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Spring Boot Profiles Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What is the active profile output?
Given a Spring Boot application with two profiles dev and prod, and the following configuration:

application.properties:
spring.profiles.active=dev

application-dev.properties:
app.message=Development Mode

application-prod.properties:
app.message=Production Mode

@Component
public class MessagePrinter {
  @Value("${app.message}")
  private String message;

  public String getMessage() {
    return message;
  }
}

What will getMessage() return when the application runs?
ADevelopment Mode
BProduction Mode
Capp.message
Dnull
Attempts:
2 left
💡 Hint
Check which profile is active in application.properties.
📝 Syntax
intermediate
2:00remaining
Which configuration activates the 'test' profile correctly?
You want to activate the 'test' profile in a Spring Boot application. Which of the following ways correctly activates the profile?
ASet environment variable SPRING_PROFILES_ACTIVE=test
BAdd <code>spring.profiles.active=test</code> in <code>application-test.properties</code>
CAdd <code>@Profile("test")</code> on the main application class
DSet <code>spring.profiles.include=test</code> in <code>application.properties</code>
Attempts:
2 left
💡 Hint
Activating a profile means telling Spring which profile to use when starting.
🔧 Debug
advanced
2:00remaining
Why does the bean not load for 'prod' profile?
Consider this Spring Boot bean:

@Component
@Profile("prod")
public class ProdService {
  // service code
}

When running with the 'dev' profile active, the application fails to find ProdService and throws a NoSuchBeanDefinitionException. Why?
ABecause @Profile only works on configuration classes, not components
BBecause the bean class is missing the @Service annotation
CBecause the 'prod' profile is not active, so the bean is not created
DBecause the bean requires a constructor argument that is missing
Attempts:
2 left
💡 Hint
Check which profile is active and how @Profile works.
❓ state_output
advanced
2:00remaining
What is the value of 'timeout' after loading profiles?
Given these property files:

application.properties:
timeout=30

application-dev.properties:
timeout=10

application-prod.properties:
timeout=60

And the active profile is set to 'prod'. What is the value of timeout injected by @Value("${timeout}")?
A10
B30
Cnull
D60
Attempts:
2 left
💡 Hint
Profile-specific properties override default properties.
🧠 Conceptual
expert
3:00remaining
How does Spring Boot resolve multiple active profiles with conflicting properties?
If you set multiple active profiles like spring.profiles.active=dev,prod and both profiles define the same property app.mode with different values, which value does Spring Boot use?
AThe value from the first profile listed in <code>spring.profiles.active</code> is used
BThe value from the last profile listed in <code>spring.profiles.active</code> is used
CSpring Boot throws an error due to conflicting properties
DSpring Boot merges both values into a list
Attempts:
2 left
💡 Hint
Think about the order Spring Boot loads profile properties.

Practice

(1/5)
1. What is the main purpose of using test profiles in a Spring Boot application?
easy
A. To run the application with special settings only during testing
B. To improve the application's runtime performance in production
C. To automatically generate test data for the application
D. To disable security features permanently

Solution

  1. Step 1: Understand test profiles concept

    Test profiles allow running the app with different settings specifically for testing purposes.
  2. Step 2: Compare options

    Only To run the application with special settings only during testing correctly describes the purpose of test profiles as special settings for tests.
  3. Final Answer:

    To run the application with special settings only during testing -> Option A
  4. Quick Check:

    Test profiles = special test settings [OK]
Hint: Test profiles isolate test settings from production [OK]
Common Mistakes:
  • Confusing test profiles with performance tuning
  • Thinking test profiles generate test data automatically
  • Assuming test profiles disable security permanently
2. Which of the following is the correct way to name a properties file for a test profile named testdb?
easy
A. application.properties.testdb
B. testdb-application.properties
C. application-testdb.properties
D. application_testdb.properties

Solution

  1. Step 1: Recall Spring Boot profile file naming

    Spring Boot uses the pattern application-{profile}.properties for profile-specific config files.
  2. Step 2: Match the pattern with the profile name

    For profile testdb, the correct file name is application-testdb.properties.
  3. Final Answer:

    application-testdb.properties -> Option C
  4. Quick Check:

    Profile file = application-{profile}.properties [OK]
Hint: Use application-{profile}.properties naming [OK]
Common Mistakes:
  • Placing profile name after .properties
  • Using underscores instead of hyphens
  • Reversing the order of profile and application
3. Given the following test class annotation:
@ActiveProfiles("test")
and two property files:
application.properties with db.url=prod-db
application-test.properties with db.url=test-db
What will be the value of db.url during this test?
medium
A. prod-db
B. test-db
C. null
D. application.properties

Solution

  1. Step 1: Understand @ActiveProfiles effect

    @ActiveProfiles("test") activates the 'test' profile for the test run.
  2. Step 2: Determine property file precedence

    Properties in application-test.properties override those in application.properties when 'test' profile is active.
  3. Final Answer:

    test-db -> Option B
  4. Quick Check:

    Active profile properties override default [OK]
Hint: Active profile properties override defaults [OK]
Common Mistakes:
  • Assuming default properties always apply
  • Confusing profile name in annotation
  • Expecting null if profile is active
4. You have a test annotated with @ActiveProfiles("dev") but the test still uses properties from application.properties instead of application-dev.properties. What is the most likely cause?
medium
A. The test class must extend a special base class to use profiles
B. The @ActiveProfiles annotation is only for production
C. Spring Boot does not support multiple profiles
D. The application-dev.properties file is missing or misnamed

Solution

  1. Step 1: Check profile file presence

    If application-dev.properties is missing or named incorrectly, Spring Boot falls back to application.properties.
  2. Step 2: Verify annotation usage

    @ActiveProfiles works for tests to activate profiles; it is not limited to production.
  3. Final Answer:

    The application-dev.properties file is missing or misnamed -> Option D
  4. Quick Check:

    Missing profile file causes fallback to default [OK]
Hint: Check profile file name and location first [OK]
Common Mistakes:
  • Thinking @ActiveProfiles is ignored in tests
  • Believing Spring Boot lacks profile support
  • Assuming inheritance is required for profiles
5. You want to run integration tests with a profile integration that uses a different database URL and disables security. Which combination correctly activates this profile and overrides the default settings?
hard
A. Create application-integration.properties with overrides and annotate tests with @ActiveProfiles("integration")
B. Add spring.profiles.active=integration only in application.properties
C. Use @Profile("integration") on the test class without any properties file
D. Set environment variable SPRING_PROFILE=integration but keep default properties unchanged

Solution

  1. Step 1: Use profile-specific properties file

    Create application-integration.properties to override database URL and security settings for the integration profile.
  2. Step 2: Activate profile in tests

    Annotate tests with @ActiveProfiles("integration") to activate the profile during test runs.
  3. Final Answer:

    Create application-integration.properties with overrides and annotate tests with @ActiveProfiles("integration") -> Option A
  4. Quick Check:

    Profile file + @ActiveProfiles activates test config [OK]
Hint: Use profile file plus @ActiveProfiles to activate [OK]
Common Mistakes:
  • Setting active profile only in default properties
  • Using @Profile instead of @ActiveProfiles on tests
  • Relying on environment variable without config changes
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