Spring Boot: Mastering Custom Auto-Configuration
Explore the intricacies of customizing auto-configuration in Spring Boot.
Questions in this quiz
12 questions on Spring Boot: Mastering Custom Auto-Configuration. Work through them here, then start the quiz to answer them and see your score.
1.What is the primary purpose of Spring Boot's auto-configuration feature?
- ATo automatically configure a Spring application based on the dependencies present on the classpath.
- BTo replace manual configuration with XML files.
- CTo provide a graphical user interface for Spring applications.
- DTo generate boilerplate code for a Spring application.
2.How can you exclude a specific auto-configuration class in Spring Boot?
- AUsing the @ExcludeAutoConfiguration annotation.
- BUsing the @SpringBootApplication(exclude = {ClassName.class}) annotation.
- CUsing the @DisableAutoConfiguration annotation.
- DRemoving the dependency from the classpath.
3.Which property is used to disable all auto-configuration in a Spring Boot application?
- Aspring.boot.autoconfiguration=false
- Bspring.autoconfigure.exclude=all
- Cspring.main.web-application-type=none
- Dspring.autoconfigure.enabled=false
4.How does Spring Boot determine which auto-configuration classes to apply?
- ABy checking the META-INF/spring.factories file.
- BBy reading a configuration file named application.properties.
- CBy scanning all classes in the application package.
- DBy analyzing the application's main method.
5.What is the role of the @ConditionalOnMissingBean annotation in auto-configuration?
- AIt replaces an existing bean with a new one.
- BIt marks a bean as optional.
- CIt prevents a bean from being created if another specific bean is present.
- DIt ensures a bean is only created if another specific bean is missing.
6.Which annotation is used to create a custom auto-configuration class?
- A@AutoConfigureOrder
- B@EnableAutoConfiguration
- C@ConditionalOnClass
- D@Configuration
7.What is the purpose of the @AutoConfigureAfter annotation?
- ATo disable auto-configuration after a certain condition is met.
- BTo configure beans only after the application starts.
- CTo ensure that the auto-configuration runs after specified configurations.
- DTo automatically configure beans after a specified time delay.
8.How can you provide custom configuration properties in a Spring Boot application?
- ABy modifying the spring.factories file.
- BBy using the @ConfigurationProperties annotation.
- CBy editing the META-INF/resources directory.
- DBy creating a custom properties file and loading it manually.
9.What is the function of the @ConditionalOnClass annotation?
- AIt marks a class as conditional for testing purposes.
- BIt prevents a bean from being created if a specified class is on the classpath.
- CIt creates a bean only if a specified class is on the classpath.
- DIt ensures a class is loaded before the application starts.
10.Which annotation would you use to specify the order of auto-configuration?
- A@Priority
- B@ConfigurationOrder
- C@Order
- D@AutoConfigureOrder
11.In which scenario would you use the @ConditionalOnProperty annotation?
- ATo load a property file conditionally.
- BTo disable a bean if a specific property exists.
- CTo ensure a property is only set after application startup.
- DTo create a bean only if a specific property is set to a certain value.
12.What is the purpose of the spring.factories file in Spring Boot?
- ATo define the order of bean initialization.
- BTo configure application properties.
- CTo register auto-configuration classes and other components.
- DTo list all available beans in the application.