Junior — Middle
How can application parameters be configured in Spring without recompiling the code?
sobes.tech AI
Answer from AI
In Spring, application parameters can be configured through external configuration files such as application.properties or application.yml. This allows changing settings without recompiling the code. You can also use environment variables or command-line arguments.
To access parameters in code, the @Value annotation or the @ConfigurationProperties bean are typically used.
Example of using @Value:
@Value("${app.timeout:30}")
private int timeout;
Here, the value of app.timeout is taken from the configuration, and if it is not present, the default value 30 is used.