Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a profile name that does not match any active environment.
Forgetting to annotate the class with @Component.
✗ Incorrect
The @Profile annotation activates the bean only when the specified profile is active. Here, 'dev' activates the bean for the development environment.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'dev' or 'test' instead of 'prod' for production beans.
Not annotating the method with @Bean.
✗ Incorrect
The @Profile annotation with 'prod' ensures this bean is created only in the production environment.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting quotes around the profile name.
Using single quotes instead of double quotes.
✗ Incorrect
The @Profile annotation requires a string literal with double quotes around the profile name.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using bitwise OR operator '|' instead of comma.
Not enclosing profiles in quotes.
✗ Incorrect
The @Profile annotation accepts multiple profiles as a comma-separated list of string literals to activate the bean for any of those profiles.
5fill in blank
hardFill 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'
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.
✗ Incorrect
The class must be annotated with @Component to be a Spring bean, @Profile("prod") to activate it only in production, and named appropriately.