As a Java developer, it is expected that you have a good understanding of Spring Framework concepts, particularly in the programming aspect. Spring Boot is a popular framework in the industry, built on top of Spring Framework itself. A strong grasp of Spring Framework will make it easier to understand and work with Spring Boot.
This article provides multiple-choice questions (MCQs) that frequently come up in interviews to refresh your understanding of Spring Framework concepts. By solving these Spring MCQs, both beginners and professionals can learn or refresh their knowledge of Spring Framework before taking a written test or an interview.
Q#1. Which annotation is not used to inject dependencies into a Spring bean?
(a) @Inject(
(b) @Bean
(c) @Autowired
(d) @Resource
Answer: (b) @Bean
Explanation: ‘@Autowired’, ‘@Resource’, and ‘@Inject’ are all used to inject dependencies. They use different implementations of post-processor classes. They all behave almost identically. The ‘@Autowired’ and ‘@Inject’ annotations use the 'AutowiredAnnotationBeanPostProcessor' to inject dependencies. ‘@Autowired’ and ‘@Inject’ can be used interchangeably to inject dependencies. Furthermore, the ‘@Resource’ annotation uses the 'CommonAnnotationBeanPostProcessor' to inject dependencies.