0
0
Spring Bootframework~10 mins

IoC container mental model 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 declare a Spring bean using annotation.

Spring Boot
@Component
public class [1]Service {
    // service logic
}
Drag options to blanks, or click blank then click option'
AUser
BAutowired
CRepository
DController
Attempts:
3 left
💡 Hint
Common Mistakes
Using annotation names like @Autowired instead of class names.
Using unrelated class names like Repository or Controller.
2fill in blank
medium

Complete the code to inject a bean using Spring's dependency injection.

Spring Boot
public class UserController {
    @[1]
    private UserService userService;
}
Drag options to blanks, or click blank then click option'
AComponent
BRepository
CAutowired
DService
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Component or @Service which are for bean declaration, not injection.
Using @Repository which is for data access layers.
3fill in blank
hard

Fix the error in the bean declaration by completing the annotation.

Spring Boot
@[1]
public class OrderService {
    // service logic
}
Drag options to blanks, or click blank then click option'
AAutowired
BRepository
CComponent
DService
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Autowired which is for injection, not declaration.
Using @Component which works but is less specific.
Using @Repository which is for data access.
4fill in blank
hard

Fill both blanks to complete the code for constructor injection in Spring.

Spring Boot
public class PaymentController {
    private final PaymentService paymentService;

    public PaymentController([1] paymentService) {
        this.[2] = paymentService;
    }
}
Drag options to blanks, or click blank then click option'
APaymentService
BpaymentService
CPaymentController
Dthis
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name as the field name.
Using 'this' instead of the field name.
5fill in blank
hard

Fill all three blanks to complete the code for a Spring configuration class defining a bean.

Spring Boot
@Configuration
public class AppConfig {

    @Bean
    public UserService [1]() {
        return new [2]();
    }

    @Bean
    public UserRepository [3]() {
        return new UserRepository();
    }
}
Drag options to blanks, or click blank then click option'
AuserService
BUserService
CuserRepository
DUserRepository
Attempts:
3 left
💡 Hint
Common Mistakes
Using class names as method names.
Mixing up method names and class names.