Spring Boot Flashcards

1
Q

What is Spring Boot?

A

Spring Boot is a set of pre-configured frameworks designed to reduce boilerplate configuration (infrastructure). Spring Boot provides OOTB ready to use infrastructure beans.

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

What are the advantages of using Spring Boot?

A

Most important advantage is easy configuration of Spring application.

Additional to this it provides something more:

  • Integrated web containers that allow for easy testing
  • Starters – sets of dependencies that help setting up a “typical” application
  • Little or no configuration
  • Decrease amount of boilerplate code

Spring boot allows:

1) Setting up the infrastructure for a Spring project in a really short time
2) Providing a default common infrastructure configuration but allowing easy divergence from the default as the application grows. So any default configuration can easily be overridden.
3) Providing a range of nonfunctional features common to a wide range of projects (embedded servers, security, metrics, health checks, externalized configuration).
4) Remove the need for XML and code configuration.

Features
* Create stand-alone Spring applications
* Embed Tomcat, Jetty or Undertow directly (no need to
deploy WAR files)
* Provide opinionated ‘starter’ POMs to simplify your
Maven configuration
* Automatically configure Spring whenever possible
* Provide production-ready features such as metrics,
health checks and externalized configuration
* Absolutely no code generation and no requirement
for XML configuration

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

Why is Spring Boot “opinionated”?

A

It is opinionated, because it provides a default common infrastructure configuration. It makes assumptions on what you need based on dependencies from the classpath.

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

How does it work? How does it know what to configure?

A

It scans dependencies from classpath and adds support for different components by initializing “maybe” required beans. For example if it sees a dependency on Thymeleaf, 3 beans that Thymeleaf uses are automatically initialized:

ThymeleafViewResolver
SpringTemplateEngine
TemplateResolver
Moreover it also scans the templates directory from resources for Thymeleaf templates.

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

What things affect what Spring Boot sets up?

A

Specified dependencies – only if @EnableAutoConfiguration or @SpringBootApplication annotations are used.

@EnableAutoConfiguration is a specific Spring Boot annotation that has the purpose to enable Spring Application Context, attempting to ques and configure beans that you are likely to need based on the specified dependencies. This annotation works well with Spring-provided starter dependencies, but it is not directly tied to them, so other dependencies outside the starters can be used. I.e. if there is a specific embedded server on the classpath, this will be used unless there is another EmbeddedServletContainerFactory configuration in the project.

@SpringBootApplication is a top-level annotation designed to use only at class level, it is equivalent to declaring the following three annotations: @Configuration, @EnableAutoConfiguration, @ComponentScan

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

How are properties defined? Where?

A

Properties may be defined either in .properties format, or in YAML format.

Default Spring names for properties files are: application.properties and application.yml.
Those default names may be changed to custom ones by setting the System property “spring.config.name” to the required property file name.

The property file mus be placed in one of the following locations relatively to the class that will use it:

1) /config subdirectory of the current directory
2) the current directory
3) classpath config package
4) the classpath root (resources package)

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

Would you recognize common Spring Boot annotations and configuration properties if you saw them in the exam?

A

@EnableAutoConfiguration - enables Spring Application Context to attempt to ques and configure beans based on the specified dependencies. This annotation works well with Spring-provided starter dependencies, but it is not directly tied to them, so other dependencies outside the starters can be used. I.e. if there is a specific embedded server on the classpath, this will be used unless there is another EmbeddedServletContainerFactory configuration in the project.

@SpringBootApplication is a top-level annotation designed to use only at class level, it is equivalent to declaring the following three annotations: @Configuration, @EnableAutoConfiguration, @ComponentScan

@ConfigurationProperties - can be used on a class that loads and holds the YAML or *.properties values. This annotation also provides the possibility to validate the external properties and define a prefix for the properties. So if there are multiple prefixes, multiple classes can be defined.

@EnableConfigurationProperties - can be used on a Configuration class. With @ConfigurationProperties annotated class name as argument it enables support for latest.

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

What is the difference between an embedded container and a WAR?

A

Embedded container is a server that comes with the resulting application whereas WAR is an archive that can be deployed on an external container.

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

What embedded containers does Spring Boot support?

A

TomCat
Jetty
Undertow

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

What is a Spring Boot starter POM? Why is it useful?

A

Starter POM is a set of spring starter dependencies.It should be defined as a parent in a Maven project to enable Spring Boot.

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

Can you control logging with Spring Boot? How?

A

Logging is initialized before the application context, so it is impossible to control logging from using @PropertySources in @Configuration classes. System properties and conventional Spring Boot external configuration files should be used.
Depending on the logging system that is used, Spring Boot will look for the specific configuration files.

The logfile name to use by default by Spring Boot can be configured using the “logging.file” Spring Environment variable.

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