0
0
Spring Bootframework~10 mins

Profile-based configuration in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to specify the active Spring profile in application.properties.

Spring Boot
spring.profiles.active=[1]
Drag options to blanks, or click blank then click option'
Adefault
Bactive
Cprofile
Ddev
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'active' or 'profile' as the profile name instead of a real profile like 'dev'.
Leaving the value empty.
2fill in blank
medium

Complete the filename to create a profile-specific properties file for the test profile.

Spring Boot
application-[1].properties
Drag options to blanks, or click blank then click option'
Aactive
Bdefault
Ctest
Dprofile
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'default' or 'active' instead of the actual profile name.
Misspelling the profile name.
3fill in blank
hard

Fix the error in the annotation to activate the prod profile in a Spring Boot test class.

Spring Boot
@ActiveProfiles("[1]")
Drag options to blanks, or click blank then click option'
Aprod
Bdefault
Cproduction
Dprofile
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'production' instead of 'prod'.
Using 'default' which is not a profile name.
4fill in blank
hard

Fill both blanks to define a bean that is only created when the dev profile is active.

Spring Boot
@Bean
@Profile([1])
public DataSource dataSource() {
    return [2];
}
Drag options to blanks, or click blank then click option'
Adev
Bprod
C"dev"
Dnew HikariDataSource()
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the profile name in @Profile.
Returning a class name instead of an instance.
5fill in blank
hard

Fill all three blanks to create a YAML profile-specific configuration for staging with a custom server port.

Spring Boot
spring:
  profiles:
    active: [1]
  server:
    port: [2]

logging:
  level:
    root: [3]
Drag options to blanks, or click blank then click option'
Astaging
B8085
CDEBUG
Dprod
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prod' instead of 'staging' for the profile.
Setting port as a string instead of a number.
Using lowercase logging levels.