32-Spring Boot - A Closer Look Flashcards

1
Q

What is defactor standard?

A

De facto standards are those which have been accepted as the best standard for their purpose
Spring Boot looks for application.properties by default

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

What locations will Spring Boot look for application.properties?

A

First, /config: subdirectory of the working directory
Then, working directory
Then, config package in the classpath
Last, classpath root

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

If no profile is active, what properties files will be loaded?

A

application.properties

application-default.properties

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

How to change the location that Spring boot looks up for properties files?

A

spring. config.location
e. g.
spring. config.location=classpath:/default.properties,classpath:/override.properties

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

How to change the default application config file that Spring boot looks for?

A

spring.config.name

default value is “application”

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

Does @PropertySource support YML config files?

A

No,

YAML is only supported when Spring Boot loads application.yml

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

How to specify multiple profiles config in a single file?

A
Using --- to separate and spring.profiles for profile name
e.g.
# Sections without spring.profiles are always loaded
# Something
---
spring:
  profiles: local
---
spring:
  profiles: cloud
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Order that Spring Boot select properties

A
  1. Devtools settings
  2. @TestPropertySource and @SpringBootTest properties
  3. Command line arguments
  4. SPRING_APPLICATION_JSON (inline JSON properties).
  5. ServletConfig / ServletContext parameters.
  6. JNDI attributes from java:comp/env
  7. Java System properties
  8. OS environment variables
  9. Profile-specific application properties
  10. Application properties / YAML
  11. @PropertySource files
  12. SpringApplication.setDefaultProperties.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the purpose of using @ConfigurationProperties?

A
e.g.
@ConfigurationProperties(prefix="rewards.client")
public class ConnectionSettings {
    // .. binding properties start with rewards.client to this class
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Is ConfigurationProperties a part of Spring framework or Spring boot?

A

It’s a part of Spring boot

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

Ways to enable @ConfigurationProperties?

A
1. @SpringBootApplication
@EnableConfigurationProperties(ConnectionSettings.class)
public class Application {}
2. @SpringBootApplication
@ConfigurationPropertiesScan
public class Application {}
3. @Component
@ConfigurationProperties(prefix="rewards.client")
public class ConnectionProperties {}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is relaxed binding?

A
Flexible in properties matching. Only applied for @ConfigurationProperties
e.g.
@ConfigurationProperties("rewards.client-connection")
class Config { String hostUrl; }
Valid matches:
1. rewards.clientConnection.hostUrl
2. rewards.client-connection.host-url
3. rewards.client_connection.host_url
4. REWARDS_CLIENTCONNECTION_HOSTURL
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

List out 6 @Conditional

A

1, 2. ConditionalOnClass, ConditionalOnMissingClass
3, 4. ConditionalOnBean, ConditionalOnMissingBean
5, 6. ConditionalOnProperty, ConditionalOnMissingProperty

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

What are the targets of @Conditional?

A

class, bean method

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

What jar file defines auto-configuration logic in Spring boot?

A

spring-boot-autoconfigure.jar

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

What are inside spring-boot-autoconfigure/META-INF/spring.factories?

A
  1. @EnableAutoConfiguration reads a factories file for list of AutoConfiguration classes used by Spring Boot
17
Q

How to configure schema and default data for DB?

A

spring. datasource.schema=/testdb/schema.sql

spring. datasource.data=/testdb/data.sql

18
Q

How to configure MySQL db connection?

A

spring. datasource.url=jdbc:mysql:…
spring. datasource.username=
spring. datasource.password=

19
Q

How to update the default log level of the application?

A

logging.level.root=INFO

20
Q

How to update the log level of a package?

A

logging.level.com.myproject=DEBUG

21
Q

Ways to exclude 1 auto-config in Spring Boot app

A
  1. @EnableAutoConfiguration(exclude=DataSourceAutoConfiguration.class)
  2. (application.yml) spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
22
Q

What pooled datasources are supported by Spring Boot?

A

Tomcat
HikariCP
Commons DBCP 1 & 2

23
Q

How to set pooled datasource type in Spring Boot?

A

spring.datasource.type=
e.g. Tomcat
HikariCP
Commons DBCP 1 & 2

24
Q

What is the order of selecting pooled data source type?

A

HikariCP (highest precedence) –> Tomcat Commons DBCP2

25
What are logging frameworks supported by Spring? What is the default
Logback(default) Java Util Logging Log4J Log4J2
26
How to set the place of logging files?
Use: logging.file.name=rewards.log OR: logging.file.path=/var/log/rewards