@SpringBootApplication — Concept Check
Questions on @SpringBootApplication. A convenience annotation combining @Configuration, @EnableAutoConfiguration, and @ComponentScan that bootstraps the entire application context.
Questions in this quiz
8 questions on @SpringBootApplication — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.Your Spring Boot application is not starting because of a missing DataSource bean. You have specified `exclude = { DataSourceAutoConfiguration.class }` in `@SpringBootApplication`. What should you do to resolve this?
- ARemove the exclude attribute for DataSourceAutoConfiguration
- BInclude DataSourceAutoConfiguration in application.properties
- CAdd a DataSource bean manually
- DChange the scanBasePackages attribute
2.A developer wants to scan components in a package different from the main application class. How can this be achieved using `@SpringBootApplication`?
- AModify application.properties
- BAdd a @ComponentScan annotation
- CUse scanBasePackages attribute
- DUse the exclude attribute
3.In your Spring Boot application, you want to disable the SecurityAutoConfiguration only for testing. What is a recommended approach?
- ADisable auto-configuration globally
- BRemove SecurityAutoConfiguration dependency
- CUse exclude attribute in @SpringBootApplication
- DSet spring.autoconfigure.exclude in application-test.properties
4.What happens if you place `@SpringBootApplication` on a class other than the main application class?
- AThe application will not start
- BThe application runs with default settings
- CAll auto-configurations are disabled
- DOnly components in the specified class's package are scanned
5.You notice that a Spring Boot application is scanning unnecessary packages, slowing down startup. How can you optimize this?
- ARemove @EnableAutoConfiguration
- BUse scanBasePackages to limit scanning
- CSwitch to explicit bean definitions
- DAdd exclude attribute for all unused configurations
6.A developer excludes RedisAutoConfiguration via application.properties but it still loads. What might be the issue?
- AThe property file is not loaded
- BThe exclude attribute is missing in @SpringBootApplication
- CRedisAutoConfiguration cannot be excluded
- DThe classpath has conflicting configurations
7.Which attribute in `@SpringBootApplication` allows you to exclude specific auto-configurations?
- AscanBasePackages
- BexcludeName
- CautoConfigureExclude
- Dexclude
8.What is the primary purpose of `@SpringBootApplication` in a Spring Boot application?
- AOnly enables auto-configuration
- BOnly marks the class as a configuration source
- CCombines configuration, auto-configuration, and component scanning
- DOnly scans for components