Spring Boot

Application Properties & YAML

Configuration with application.properties/yml, @Value, @ConfigurationProperties, profiles, external properties

16 domande da colloquio·
Junior
1

What is the main difference between application.properties and application.yml in Spring Boot?

Risposta

Both files are used to configure Spring Boot, but use different formats. YAML format (.yml) allows hierarchical structure with indentation, making it more readable for complex configurations. Properties format (.properties) uses flat key=value syntax. Spring Boot automatically loads either one, with priority to .properties if both exist.

2

Which property allows changing the embedded server port in Spring Boot?

Risposta

The server.port property configures the HTTP port of the embedded server (Tomcat, Jetty, Undertow). By default, Spring Boot starts on port 8080. This property can be defined in application.properties (server.port=9000) or in YAML (server: port: 9000). It can also be overridden via JVM argument (-Dserver.port=9000) or environment variable.

3

How to declare the property spring.datasource.url in YAML for a local PostgreSQL database?

Risposta

In YAML, hierarchical properties use indentation (spaces, not tabs). The property spring.datasource.url breaks down into spring → datasource → url. Each level is indented by 2 spaces. This hierarchical structure makes configuration more readable than the flat properties version (spring.datasource.url=jdbc:postgresql://localhost:5432/mydb).

4

How to activate the 'dev' profile at startup of a Spring Boot application?

5

Which annotation allows injecting a configuration property into a Spring bean?

+13 domande da colloquio

Padroneggia Spring Boot per il tuo prossimo colloquio

Accedi a tutte le domande, flashcards, test tecnici, esercizi di code review e simulatori di colloquio.

Inizia gratis