Application Properties & YAML
Configuration with application.properties/yml, @Value, @ConfigurationProperties, profiles, external properties
1What is the main difference between application.properties and application.yml in Spring Boot?
What is the main difference between application.properties and application.yml in Spring Boot?
답변
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.
2Which property allows changing the embedded server port in Spring Boot?
Which property allows changing the embedded server port in Spring Boot?
답변
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.
3How to declare the property spring.datasource.url in YAML for a local PostgreSQL database?
How to declare the property spring.datasource.url in YAML for a local PostgreSQL database?
답변
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).
How to activate the 'dev' profile at startup of a Spring Boot application?
Which annotation allows injecting a configuration property into a Spring bean?
+13 면접 질문