Spring Boot Flashcards
What are the 3 annotations that make up @SpringBootApplication?
- @SpringBootConfiguration
- @ComponentScan
- @EnableAutoConfiguration
Which annotation can you use to scan for components defined outside of the main package?
@SpringBootApplication(scanBasePackages=String[])
What are the 2 steps necessary to load profile-specific application.properties?
@Profile(profileName)
application-[profileName].properties
What are the 4 ways to disable auto-configuration?
- Define your own beans
- application.properties
spring.autoconfigure.exclude=[package]
@SpringBootApplication(exclude=Class[])
True or False
Spring related properties should be defined in application.properties and non-spring related properties should be defined elsewhere
True
What does SpringApplication.run()
return?
ConfigurableApplicationContext which is a subtype of ApplicationContext
How can you change the logging level of a Spring Boot application?
logging.level.[package]=?
INFO is the default logging level
Does Spring Boot autoconfigure a datasource if an embedded database is used?
Yes. For example, when HSQLDB is used, Spring boot will autoconfigure a datasource
Is application.properties loaded before other property files?
Yes
What is the command to build a Spring Boot executable with Maven?
./mvnw package
Which file will always load?
- application-local.properties
- application-cloud.properties
- application.properties
application.properties
What is the syntax for adding command line properties to a Spring Boot application?
--key=value
True or False
If you define a set of configuration keys for your own components, we recommend you group them in a POJO annotated with @ConfigurationProperties
True
True or False
spring.profiles.include
overrides existing properties when used
False
True or False
When Jackson is on the classpath an ObjectMapper bean is automatically configured
True
True or False
Unlike a nested @Configuration class, which would be used instead of your application’s primary configuration, a nested @TestConfiguration class is used in addition to your application’s primary configuration.
True
True or False
Regardless of your classpath, meter registries, except the in-memory backed, are not auto-configured when using @SpringBootTest.
If you need to export metrics to a different backend as part of an integration test, annotate it with @AutoConfigureObservability
True
True or False
It is possible to include multiple slices in a test class
False
True or False
Make sure to not use the regular @Import annotation to import auto-configurations as they are handled in a specific way by Spring Boot
True
Use @ImportAutoConfiguration
instead
Since your @SpringBootApplication
class is used by default as the configuration for your tests, it is important not to litter the application’s main class with configuration settings that are specific to a particular area of its functionality
For example:
@SpringBootApplication @EnableMongoAuditing public class MyApplication { // ... }
True
@EnableMongoAuditing
should be moved to its own configuration class