0
0
Spring Bootframework~20 mins

Environment-based profiles in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 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
How does Spring Boot select active profiles at runtime?

Consider a Spring Boot application with multiple profiles defined: dev, test, and prod. If the application is started with the JVM argument -Dspring.profiles.active=test, what will be the active profile during runtime?

ANo profile is active because JVM arguments do not affect Spring profiles.
BOnly the <code>test</code> profile is active.
CAll profiles <code>dev</code>, <code>test</code>, and <code>prod</code> are active.
DThe <code>prod</code> profile is active by default, ignoring the JVM argument.
Attempts:
2 left
💡 Hint

Think about how Spring Boot reads the spring.profiles.active property.

📝 Syntax
intermediate
2:00remaining
Which YAML snippet correctly activates the 'prod' profile in Spring Boot?

Given the following YAML configuration, which option correctly sets the active profile to prod?

Spring Boot
spring:
  profiles:
    active: ???
Aactive: prod
Bactive: 'prod'
Cactive: [prod]
D
active:
  - prod
Attempts:
2 left
💡 Hint

Remember how simple string values are set in YAML.

🔧 Debug
advanced
2:00remaining
Why does the 'dev' profile not activate despite being set in application.properties?

Given these two files:

application.properties:
spring.profiles.active=dev

application-dev.properties:
logging.level.root=DEBUG

The application logs do not show DEBUG level logs. What is the most likely cause?

AThe logging level property is misspelled in <code>application-dev.properties</code>.
BThe <code>application-dev.properties</code> file is not named correctly.
CThe <code>spring.profiles.active</code> property is overridden by an environment variable or JVM argument.
DSpring Boot does not support profile-specific properties files.
Attempts:
2 left
💡 Hint

Check if any external settings override the active profile.

state_output
advanced
2:00remaining
What is the output of this Spring Boot profile conditional bean registration?

Consider this Spring Boot component:

@Component
@Profile("prod")
public class ProdService {
    public String getMessage() {
        return "Production Service";
    }
}

If the active profile is dev, what happens when the application tries to get ProdService bean?

ASpring throws a <code>NoSuchBeanDefinitionException</code> because <code>ProdService</code> is not loaded.
BSpring creates <code>ProdService</code> bean anyway ignoring the profile.
CSpring creates a proxy <code>ProdService</code> bean that returns null.
DSpring logs a warning but creates the bean.
Attempts:
2 left
💡 Hint

Think about how @Profile controls bean creation.

🧠 Conceptual
expert
3:00remaining
How does Spring Boot merge properties from multiple active profiles?

If a Spring Boot application activates two profiles simultaneously: dev and featureX, and both have application-dev.properties and application-featureX.properties files with overlapping keys, how does Spring Boot resolve the final property values?

AOnly properties from the first profile listed in <code>spring.profiles.active</code> are used.
BProperties from all profiles are merged, and the first profile listed overrides later ones.
CSpring Boot throws an error if multiple profiles define the same property.
DProperties from the last profile listed in <code>spring.profiles.active</code> override earlier ones.
Attempts:
2 left
💡 Hint

Consider the order of profiles in the spring.profiles.active property.