0
0
Spring Bootframework~10 mins

Why IoC matters in Spring Boot - Test Your Understanding

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

Complete the code to declare a Spring component using IoC.

Spring Boot
@[1]
public class MyService {
    // service logic
}
Drag options to blanks, or click blank then click option'
AService
BComponent
CAutowired
DRepository
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Autowired instead of a component annotation
Using @Repository for a service class
2fill in blank
medium

Complete the code to inject a dependency using IoC in Spring.

Spring Boot
public class MyController {
    @[1]
    private MyService myService;
}
Drag options to blanks, or click blank then click option'
AComponent
BAutowired
CService
DInject
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Component instead of @Autowired
Using @Service on fields
3fill in blank
hard

Fix the error in the code to properly use IoC for dependency injection.

Spring Boot
public class MyController {
    private MyService myService;

    public MyController([1] MyService myService) {
        this.myService = myService;
    }
}
Drag options to blanks, or click blank then click option'
A@Autowired
BAutowired
C@Inject
DInject
Attempts:
3 left
💡 Hint
Common Mistakes
Missing @ symbol
Using plain 'Autowired' without @
Using @Inject without proper setup
4fill in blank
hard

Fill both blanks to create a Spring bean and inject it using IoC.

Spring Boot
@[1]
public class NotificationService {
}

public class UserController {
    @[2]
    private NotificationService notificationService;
}
Drag options to blanks, or click blank then click option'
AComponent
BAutowired
CService
DInject
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Service instead of @Component here
Forgetting @Autowired on the field
5fill in blank
hard

Fill all three blanks to define a Spring service, inject it, and use it in a method.

Spring Boot
@[1]
public class EmailService {
    public void sendEmail() {
        System.out.println("Email sent");
    }
}

public class NotificationController {
    @[2]
    private EmailService emailService;

    public void notifyUser() {
        emailService.[3]();
    }
}
Drag options to blanks, or click blank then click option'
AService
BAutowired
CsendEmail
DComponent
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Component instead of @Service for service class
Forgetting to call the method
Missing @Autowired annotation