Spring Boot Auto Configurations MCQ - Multiple Choice Questions and Answers

Spring Boot Auto Configuration aims to reduce the developer's need to define beans in the configuration file. Whether you're a newbie discovering the realms of Spring Boot or simply want to refresh your foundational knowledge, this MCQ guide on Spring Boot Auto Configurations is your handy companion. Let's jump in!

1. What is the main objective of Spring Boot Auto Configuration?

a) Automate the build process
b) Provide default application settings
c) Automatically configure Spring beans based on classpath settings
d) Monitor and manage Spring Boot applications

Answer:

c) Automatically configure Spring beans based on classpath settings

Explanation:

Auto Configuration's primary goal is to simplify Spring application setups by configuring beans automatically based on the libraries present on the classpath.

2. How can you disable a specific auto-configuration?

a) Using @DisableAutoConfiguration
b) By removing the corresponding starter dependency
c) Using @EnableAutoConfiguration(exclude=…)
d) By setting the property spring.autoconfig.disable=true

Answer:

c) Using @EnableAutoConfiguration(exclude=…)

Explanation:

You can exclude specific auto-configurations using the @EnableAutoConfiguration annotation with its exclude attribute.

3. Which file is responsible for listing all the auto-configuration classes in Spring Boot?

a) spring.factories
b) spring-boot-autoconfig.jar
c) application.properties
d) pom.xml

Answer:

a) spring.factories

Explanation:

The spring.factories file inside the META-INF directory lists all the auto-configuration classes.

4. What annotation is typically used with main application class to enable auto-configuration?

a) @AutoConfig
b) @BootApplication
c) @SpringBootApplication
d) @EnableSpring

Answer:

c) @SpringBootApplication

Explanation:

The @SpringBootApplication annotation includes @EnableAutoConfiguration and is typically used with the main application class to enable auto-configuration.

5. If two beans of the same type are defined, and you don't specify which one to autowire, what happens?

a) Both beans are autowired
b) An error occurs
c) The first bean is autowired
d) None are autowired

Answer:

b) An error occurs

Explanation:

If there are two beans of the same type and no specific bean is chosen for autowiring, Spring throws a 'No qualifying bean of type' exception.

6. Which of the following is NOT a feature of Spring Boot Auto Configuration?

a) Reducing the need for specifying beans
b) Creating embedded servlet container beans
c) Automatic property validation
d) Generating template beans when required dependencies are in the classpath

Answer:

c) Automatic property validation

Explanation:

While auto configuration reduces bean specifications, manages embedded servlets, and creates template beans, it doesn't handle property validation by itself.

7. How can you find out what auto-configurations have been applied?

a) Reviewing the spring.factories file
b) Using the /autoconfig actuator endpoint
c) Checking the pom.xml file
d) Through the @ListAutoConfigurations annotation

Answer:

b) Using the /autoconfig actuator endpoint

Explanation:

The /autoconfig actuator endpoint provides insights on which auto-configurations have been applied and which have not.

8. What property can be set to trace the conditions evaluated during auto-configuration?

a) spring.debug.enable=true
b) spring.boot.trace=true
c) spring.autoconfigure.trace=true
d) debug=true

Answer:

d) debug=true

Explanation:

Setting the debug property to true allows tracing the conditions that were evaluated during auto-configuration.

9. In which package is the primary auto-configuration logic for Spring Boot located?

a) org.springframework.boot.autoconfigure
b) org.springframework.boot.config
c) org.springframework.boot.autoconfig
d) org.springframework.boot.setup

Answer:

a) org.springframework.boot.autoconfigure

Explanation:

The main auto-configuration logic is present in the org.springframework.boot.autoconfigure package.

10. When does Spring Boot apply auto-configuration?

a) After any user-defined beans are registered
b) Before any user-defined beans are registered
c) Concurrently with user-defined beans registration
d) Only if no user-defined beans are present

Answer:

a) After any user-defined beans are registered

Explanation:

Spring Boot applies auto-configuration after all user-defined beans have been registered.

11. To explicitly define the order of auto-configuration, which annotation should be used?

a) @AutoConfigOrder
b) @ConfigOrder
c) @ConfigurationOrder
d) @Order

Answer:

d) @Order

Explanation:

The @Order annotation can be used to explicitly define the order in which auto-configurations should be applied.

12. Which Spring Boot starter is fundamental to enable auto-configuration?

a) spring-boot-starter-config
b) spring-boot-starter-autoconfig
c) spring-boot-starter
d) spring-boot-autoconfigure

Answer:

d) spring-boot-autoconfigure

Explanation:

The spring-boot-autoconfigure starter contains the auto-configuration support necessary for Spring Boot applications.


Related Spring Boot MCQ Posts

Comments