Welcome to the Spring Configuration MCQ (Multiple Choice Questions) guide, Here, we present a set of MCQ questions to test your knowledge of Spring Configurations, different types of Spring Configurations, and associated annotations.
Note that each question is followed by the correct answer and an explanation to help reinforce your knowledge.
1. Which of the following is a traditional way to configure beans in Spring?
Answer:
Explanation:
XML has been the traditional way to configure beans in Spring before the advent of annotation-based and Java-based configurations.
2. Which annotation is used to specify a Spring configuration class?
Answer:
Explanation:
The @Configuration annotation indicates that a class declares one or more @Bean methods and may be processed by the Spring container.
3. Which of the following annotations enables component scanning in Spring?
Answer:
Explanation:
The @ComponentScan annotation is used with @Configuration to specify the packages to scan for annotated components.
4. If you want to import another configuration class, which annotation would you use?
Answer:
Explanation:
The @Import annotation allows for loading @Bean definitions from another configuration class.
5. Which of the following is NOT a way to configure beans in Spring?
Answer:
Explanation:
Spring does not support Excel-based configurations. The primary methods are XML, annotation, and Java configurations.
6. Which annotation can be used to inject a value from a properties file?
Answer:
Explanation:
The @Value annotation is used to inject values from properties files or literals into fields or method parameters.
7. In Java-based configuration, which method is used to register a bean?
Answer:
Explanation:
The @Bean annotation is used in Java configuration classes to indicate that a method produces a bean to be managed by the Spring container.
8. Which of the following is true for @Component annotation?
Answer:
Explanation:
@Component is a generic stereotype for indicating a class is a Spring component. It's an umbrella for other annotations like @Service, @Repository, and @Controller.
9. To inject configuration properties in a type-safe manner, which annotation would you use on a class?
Answer:
Explanation:
The @ConfigurationProperties annotation allows you to map configuration properties to a POJO in a type-safe manner.
10. To externalize configuration to properties files, which annotation should be paired with @Configuration?
Answer:
Explanation:
The @PropertySource annotation is used along with @Configuration to specify the path to properties files.
11. In a Spring Boot application, which file is commonly used to externalize configuration?
Answer:
Explanation:
Spring Boot applications often use the application.properties file to externalize configuration. There's also an application.yml variant for those who prefer YAML format.
12. Which annotation in Spring can be used to inject values directly from the application's environment?
Answer:
Explanation:
The @Value annotation can be used to inject values from various sources, including the application's environment, by specifying placeholders, for instance: @Value("${envVariableName}").
Related Spring MCQ Posts
- Spring IOC Container MCQ - Multiple Choice Questions and Answers
- Spring Dependency Injection MCQ - Multiple Choice Questions and Answers
- Spring Beans MCQ - Multiple Choice Questions and Answers
- Spring Configuration MCQ - Multiple Choice Questions and Answers
- Spring AOP MCQ - Multiple Choice Questions and Answers
- Spring JDBC MCQ - Multiple Choice Questions and Answers
- Spring Data MCQ - Multiple Choice Questions and Answers
- Spring Messaging MCQ - Multiple Choice Questions and Answers
- Spring Batch MCQ - Multiple Choice Questions and Answers
- Spring WebFlux MCQ - Multiple Choice Questions and Answers
- Spring Testing Quiz - MCQ - Multiple Choice Questions
- Spring Security Quiz - MCQ - Multiple Choice Questions
Comments
Post a Comment
Leave Comment