0 day streak
java / beginner
Snippet

Configuration Injection with @Value

The @Value annotation is used to inject values from properties files into your beans. You can also provide default values if the property is missing.

snippet.java
java
1
2
3
4
5
@Component
public class AppSettings {
@Value("${app.timeout:3000}")
private int timeout;
}
spring
Breakdown
1
@Value("${app.timeout:3000}")
Reads the property 'app.timeout' from application.properties, defaulting to 3000.
2
private int timeout
The field where the injected configuration value is stored.