What methods can be used to manage Spring settings during application configuration?
sobes.tech AI
Answer from AI
In Spring, application settings can be managed in the following main ways:
-
application.properties or application.yml — standard configuration files where parameters are set in key-value format.
-
Annotations @Value and @ConfigurationProperties — allow injecting values from configuration files directly into class fields.
-
Java configuration using @Configuration and @Bean — programmatic definition of beans and their parameters.
-
Spring Profiles (@Profile) — enable different configurations depending on the active profile (e.g., dev, prod).
-
Command line arguments and environment variables — settings can be overridden without changing files.
-
Using PropertySource — connecting additional property sources.
Example of using @ConfigurationProperties:
@ConfigurationProperties(prefix = "app")
public class AppProperties {
private String name;
private int timeout;
// getters and setters
}
And in application.yml:
app:
name: MyApp
timeout: 5000
Thus, Spring provides flexible ways to manage settings during configuration.