Spring Boot Flashcards

1
Q

What are the 3 annotations that make up @SpringBootApplication?

A
  1. @SpringBootConfiguration
  2. @ComponentScan
  3. @EnableAutoConfiguration
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which annotation can you use to scan for components defined outside of the main package?

A

@SpringBootApplication(scanBasePackages=String[])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the 2 steps necessary to load profile-specific application.properties?

A
  1. @Profile(profileName)
  2. application-[profileName].properties
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the 4 ways to disable auto-configuration?

A
  1. Define your own beans
  2. application.properties
  3. spring.autoconfigure.exclude=[package]
  4. @SpringBootApplication(exclude=Class[])
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

True or False

Spring related properties should be defined in application.properties and non-spring related properties should be defined elsewhere

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does SpringApplication.run() return?

A

ConfigurableApplicationContext which is a subtype of ApplicationContext

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How can you change the logging level of a Spring Boot application?

A

logging.level.[package]=?

INFO is the default logging level

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Does Spring Boot autoconfigure a datasource if an embedded database is used?

A

Yes. For example, when HSQLDB is used, Spring boot will autoconfigure a datasource

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is Spring Boot’s property source order?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Is application.properties loaded before other property files?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the command to build a Spring Boot executable with Maven?

A

./mvnw package

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Which file will always load?

  1. application-local.properties
  2. application-cloud.properties
  3. application.properties
A

application.properties

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the syntax for adding command line properties to a Spring Boot application?

A

--key=value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

True or False

spring.profiles.include overrides existing properties when used

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

True or False

When Jackson is on the classpath an ObjectMapper bean is automatically configured

A

True

17
Q

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.

A

True

18
Q

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

A

True

19
Q

True or False

It is possible to include multiple slices in a test class

A

False

20
Q

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

A

True

Use @ImportAutoConfiguration instead

21
Q

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 {

    // ...

}
A

True

@EnableMongoAuditing should be moved to its own configuration class