Spring: @Value reads a property, with a default after the colon

The default makes the app start without the property being set anywhere.

Code
@Value("${app.page-size:20}")
private int pageSize;

@Value("${app.tags:a,b,c}")
private List<String> tags;      // comma-separated binds to a List

@Value("#{systemEnvironment['HOME']}")
private String home;            // SpEL
Output
pageSize = 20 when app.page-size is absent
tags = [a, b, c]
Advertisement

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-11