Spring Framework & IoC — Concept Check
Questions on Spring Framework & IoC. The Spring Framework is built on Inversion of Control (IoC) — you declare what you need, the container creates and wires it. Understanding the IoC container is the foundation of everything else in Spring.
Questions in this quiz
8 questions on Spring Framework & IoC — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer uses field injection in a Spring service class. What is a potential drawback of this approach?
- AFails fast at startup if dependency is missing
- BHidden dependencies make testing difficult
- CDependencies are immutable
- DSupports optional dependencies
2.In a Spring application, you notice that a bean is not being initialized eagerly. What might be the cause?
- AMissing @Autowired annotation
- BUsing setter injection
- CUsing BeanFactory instead of ApplicationContext
- DIncorrectly configured @ComponentScan
3.A service class in Spring uses setter injection. What is a likely reason for this choice?
- ATo hide dependencies
- BTo handle optional dependencies
- CTo ensure immutability
- DTo fail fast if a dependency is missing
4.What happens when SpringApplication.run() is called in a Spring Boot application?
- AScans for beans without annotations
- BInitializes beans using field injection
- CDirectly interacts with BeanFactory
- DCreates an AnnotationConfigServletWebServerApplicationContext
5.A developer claims that constructor injection in Spring requires the @Autowired annotation. Is this true?
- AYes, it's always required
- BYes, but only for setter injection
- CNo, it's optional if there's one constructor
- DNo, it's never used in constructor injection
6.In a Spring application, what is the primary role of the ApplicationContext?
- AHandles HTTP requests
- BDirectly interacts with database
- CManages thread pools
- DManages bean lifecycle and dependencies
7.If a bean is missing a required dependency in Spring, what is the likely outcome?
- AApplication runs with warnings
- BSpring uses default implementations
- CBean is created with null dependencies
- DApplication fails to start
8.What is the benefit of using constructor injection over field injection in Spring?
- AEasier to hide dependencies
- BDependencies are final and immutable
- CReduces boilerplate code
- DAllows for optional dependencies