Quick revision
The short answer
${...} is a property placeholder: Spring looks the key up in the Environment and inserts its value, and the part after the colon, as in @Value("${app.timeout:5s}"), is the default used when the property is missing. #{...} is a SpEL expression that Spring evaluates, so it can compute, call methods or reference beans, as in @Value("#{${app.limit:10} * 2}"). In both cases Spring then converts the result to the field's type, such as an int, a Duration or a List built from a comma-separated string.
What to remember
In this answer, we saw that ${...} is a property placeholder resolved from the Environment, with an optional default after the colon, and that #{...} is a SpEL expression that can compute, call methods and reference beans. Spring resolves placeholders first and evaluates expressions second, which is why #{${app.limit:10} * 2} works and why string placeholders inside expressions need quotes. Finally, Spring converts the result to the field type, including Durations and comma-separated lists.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
${...} is a property placeholder: Spring looks the key up in the Environment and inserts its value, and the part after the colon, as in @Value("${app.timeout:5s}"), is the default used when the property is missing. #{...} is a SpEL expression that Spring evaluates, so it can compute, call methods or reference beans, as in @Value("#{${app.limit:10} * 2}"). In both cases Spring then converts the result to the field's type, such as an int, a Duration or a List built from a comma-separated string.
Why this question is asked
@Value is often the first way we meet configuration in Spring, and the two kinds of brackets look almost the same, so they are easy to mix up. Mixing them up leads to real bugs: an expression that is treated as plain text, a default that never applies, or a startup failure for a missing property. Interviewers ask this to see whether we understand where values come from and when they are resolved. In this answer, we will recap what @Value does, look at placeholders and their defaults, then SpEL expressions, see how the two combine, and finish with type conversion.
1A Quick Recap of @Value
@Value is an annotation that puts a value into a field, a constructor parameter or a method parameter of a Spring bean when the bean is created. The value is written as a string inside the annotation, and that string can contain two kinds of special syntax. Spring processes them in a fixed order: first it replaces placeholders written as ${...}, then it evaluates expressions written as #{...}, and finally it converts the resulting value to the type of the field.
The values come from the Environment, the object that holds all the property sources of the application: application.yml, environment variables, system properties, command-line arguments and so on. Placeholders read from it directly; expressions can read from it, from beans and from almost anything else.
2Property Placeholders and Their Defaults
A placeholder ${key} asks the Environment for the property called key and inserts its value as text. If the property is missing, Spring Boot fails at startup with an error saying it could not resolve the placeholder, which is usually what we want for a required setting. To make the property optional, we add a default after a colon.
Notice that the default is text too, and that everything after the first colon is the default. A default can even contain another placeholder, as in ${app.url:${base.url}}, which Spring resolves in turn. Placeholders never compute anything: ${app.limit * 2} would look for a property literally named 'app.limit * 2'.
3SpEL Expressions
#{...} contains an expression in the Spring Expression Language, SpEL for short. SpEL is a small language that can do arithmetic and comparisons, call methods, read bean properties, call static methods with T(...), and provide defaults with the Elvis operator ?:, which returns its left side unless that side is null.
The last line shows the combination that confuses people most. Spring first resolves the placeholder, so the expression becomes #{'shop'.toUpperCase()}. The quotes around the placeholder matter: without them, SpEL would see shop as a name to look up, not as a string.
4Combining Them With a Default
The question's example, #{${app.limit:10} * 2}, uses both steps. First the placeholder is replaced: if app.limit is 25, the string becomes #{25 * 2}; if app.limit is missing, it becomes #{10 * 2}. Then SpEL evaluates the arithmetic.
- Resolve ${...} placeholders
app.limitmissing, so use the default 10 - Text is now #{10 * 2}the placeholder was replaced as text
- Evaluate the SpEL expression10 * 2 = 20
- Convert to the field typeint 20
4 steps in order. Play them, or step through them one at a time.
Because the placeholder is pasted in as text before SpEL sees it, it must produce something SpEL can parse. A number works without quotes; a string needs quotes as in the toUpperCase example.
5Type Conversion of the Result
Whatever the placeholder or expression produces, Spring converts it to the declared type. This is why we can write int, boolean, Duration or List fields rather than parsing strings ourselves. In Spring Boot, the application's conversion service also understands simple duration and data size formats such as 5s, 500ms or 10MB.
The last line is a reminder that conversion follows rules we should know: a plain number converted to a Duration is read as milliseconds, so it is better to always write the unit. When many related values need conversion and validation, @ConfigurationProperties is a better fit than a growing list of @Value fields.
6Follow-up questions
What happens if I write #{app.name} instead of ${app.name}?
SpEL treats app as the name of a bean or variable and fails, usually with an error saying the property or field cannot be found on the evaluation context. Properties from the Environment are not variables in SpEL. Use ${app.name}, or inside an expression use the placeholder in quotes, '${app.name}', or environment['app.name'].
Can I use ${...} and #{...} outside @Value?
Placeholders work in many annotation attributes, such as @Scheduled(cron = "${jobs.cron}") and @KafkaListener(topics = "${app.topic}"), and in XML configuration. SpEL appears in @Cacheable keys, @PreAuthorize, @EventListener conditions and @ConditionalOnExpression. Each place documents what it supports, so check before assuming.
Is there a way to make a missing placeholder resolve to null?
Yes, an empty default ${app.region:} gives an empty string, and #{null} as a default inside SpEL, as in ${app.region:#{null}}, gives null. Whether a null is a good idea is another matter; usually a real default or an Optional in @ConfigurationProperties is clearer.
7Conclusion
In this answer, we saw that ${...} is a property placeholder resolved from the Environment, with an optional default after the colon, and that #{...} is a SpEL expression that can compute, call methods and reference beans. Spring resolves placeholders first and evaluates expressions second, which is why #{${app.limit:10} * 2} works and why string placeholders inside expressions need quotes. Finally, Spring converts the result to the field type, including Durations and comma-separated lists.
Open with
The dollar form, ${...}, is a property placeholder. Spring looks the key up in the Environment, so in application.yml, environment variables, system properties and so on, and pastes the value in as text.
Then, if they want more
If the key is missing, Spring Boot fails at startup, unless I give a default after the colon, like ${app.timeout:5s}. The hash form, #{...}, is a SpEL expression that Spring evaluates, so it can do arithmetic, call methods, call static methods with T, read bean properties, or use the Elvis operator for a default, like systemProperties['region'] ?: 'eu'.
The order matters: placeholders are resolved first, then the expression is evaluated. So #{${app.limit:10} * 2} first becomes #{10 * 2} when the property is missing, and then evaluates to 20. Because the placeholder is pasted in as text, a string value needs quotes inside the expression, like #{'${app.name}'.toUpperCase()}.
After that, Spring converts the result to the field type, so I can declare an int, a boolean, a Duration such as 5s in Spring Boot, or a List from a comma-separated value. For one or two simple values @Value is fine; for a group of related settings I would use ConfigurationProperties instead.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Core technologies
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What is the difference between ${...} and #{...} in a Spring @Value annotation? Give...": https://scrivio-interview-library.netlify.app/spring-boot/spring-configuration/589d08a82b/