2V0-72-22 practice question 4 of 15

Which two statements are correct regarding Spring Boot auto-configuration customization? (Choose two.)

Full set: 79 questions
Answer options
A:

A. Use the @AutoConfigureAfter or @AutoConfigureBefore annotations to apply configuration in a specific order.

Correct answer
B:

B. Disable specific auto-configuration classes by using the exclude attribute on the @EnableAutoConfiguation annotation.

Correct answer
C:

C. Provide customized auto-configuration by subclassing the provided Spring Boot auto-configuration classes.

D:

D. Enable component scanning within auto-configuration classes to find necessary components.

E:

E. Control the order of auto-configuration classes applied with @AutoConfigureOrder.

Correct Answer:
A. A. Use the @AutoConfigureAfter or @AutoConfigureBefore annotations to apply configuration in a specific order.; B. B. Disable specific auto-configuration classes by using the exclude attribute on the @EnableAutoConfiguation annotation.
Explanation

Spring Boot's auto-configuration is highly customizable. Two primary methods for customization are ordering and exclusion. To control the sequence of auto-configuration, developers can use @AutoConfigureAfter or @AutoConfigureBefore on their configuration classes to establish a relative order. To prevent an auto-configuration class from being applied, it can be disabled using the exclude attribute on the @EnableAutoConfiguration annotation (which is meta-annotated on @SpringBootApplication).

Why Incorrect

C. Subclassing Spring Boot's auto-configuration classes is discouraged; the preferred method is to define your own beans, which will override the defaults.
D. Auto-configuration classes are loaded via a dedicated mechanism (spring.factories or auto-configuration imports) and should not use general component scanning.
E. While @AutoConfigureOrder is a valid annotation for absolute ordering, options A and B represent two distinct and fundamental customization techniques (relative ordering and exclusion), making them the best pair of answers.

References

1. Spring Boot Reference Documentation. Section: "Disabling Specific Auto-configuration Classes". "If you find that specific auto-configuration classes are being applied that you do not want, you can use the exclude attribute of @EnableAutoConfiguration to disable them".

2. Spring Boot Reference Documentation. Section: "Ordering Auto-configuration". "If you want to order configurations that should be applied after/before some other auto-configurations, you can use the @AutoConfigureAfter or @AutoConfigureBefore annotations."

Scroll to Top