0
0
Spring Bootframework~10 mins

@Profile for environment-specific beans 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 activate a bean only for the 'dev' environment.

Spring Boot
@Profile("[1]")
@Component
public class DevService {}
Drag options to blanks, or click blank then click option'
Adefault
Bprod
Cdev
Dtest
Attempts:
3 left
💡 Hint
Common Mistakes
Using a profile name that does not match any active environment.
Forgetting to annotate the class with @Component.
2fill in blank
medium

Complete the code to define a bean active only when the 'prod' profile is set.

Spring Boot
@Profile("[1]")
@Bean
public DataSource dataSource() {
    return new DataSource();
}
Drag options to blanks, or click blank then click option'
Alocal
Bprod
Ctest
Ddev
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'dev' or 'test' instead of 'prod' for production beans.
Not annotating the method with @Bean.
3fill in blank
hard

Fix the error in the annotation to activate the bean only for the 'test' profile.

Spring Boot
@Profile([1])
@Component
public class TestService {}
Drag options to blanks, or click blank then click option'
A"test"
Btest
C'test'
D["test"]
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting quotes around the profile name.
Using single quotes instead of double quotes.
4fill in blank
hard

Fill both blanks to create a bean active for either 'dev' or 'test' profiles.

Spring Boot
@Profile([1])
@Component
public class MultiEnvService {}
Drag options to blanks, or click blank then click option'
A{"dev", "test"}
B"dev"
C"dev" | "test"
D"dev", "prod"
Attempts:
3 left
💡 Hint
Common Mistakes
Using bitwise OR operator '|' instead of comma.
Not enclosing profiles in quotes.
5fill in blank
hard

Fill all three blanks to define a bean active only when the 'prod' profile is active and annotate it as a component.

Spring Boot
[1]
@Profile([2])
public class [3] {}
Drag options to blanks, or click blank then click option'
A@Component
B"prod"
CProdService
D@Service
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Service instead of @Component if the question expects @Component.
Omitting quotes around the profile name.
Using a class name that does not match the profile.