🔴 The Error You're Seeing

Confirm this matches your console output. If it does, you're in the right place.

ERROR LOG2026-02-14 21:05:18.200 ERROR 8842 --- [ main] o.s.boot.SpringApplication : Application run failed java.lang.IllegalArgumentException: Could not resolve placeholder 'app.secret' in value "${app.secret}"

⚡ Quick Fix Works 80% of the time

Add a default value to your @Value annotation using a colon.

@Value("${app.secret:default-secret-key}") private String secret;

🧠 Why this Happens

Tap to expand the deep technical explanation

You used the @Value annotation to inject a configuration property. When Spring started, it searched all application.properties, application.yml, and environment variables for that key, but couldn't find it anywhere, causing a crash.

The HITEC City Parking Spot Analogy:

A mailman is given a letter to deliver to '123 Main St', but that address doesn't exist in the city. The mailman (Spring) stops working because they cannot resolve the destination.

🔁 How to Reproduce Confirm this is your error

Reference ${app.secret} with @Value in a bean but never define app.secret in application.properties, then start the app. Spring throws IllegalArgumentException: Could not resolve placeholder 'app.secret'.

🛠️ Solutions (3 Ways to Fix)

Solution 1✓ Most common cause

Provide a default value in @Value

👉 Use this if the property is optional or you want a fallback for local development.

Adding a colon and a default value inside the @Value annotation prevents Spring from crashing if the property is missing.

@Value("${app.secret:my-default-secret}") private String secret;
Solution 2

Add the property to application.properties

👉 Use this if the property is mandatory and should be in your config file.

Ensure the property key exactly matches the placeholder string (case-sensitive).

# application.properties app.secret=my-super-secret-key
Solution 3

Inject via Environment object instead

👉 Use this if you need to check multiple properties dynamically.

Instead of @Value, inject the Environment object and use getProperty, which returns null instead of crashing if missing.

@Autowired private Environment env; public void doSomething() { String secret = env.getProperty("app.secret"); if (secret == null) { throw new RuntimeException("Secret must be set"); } }

📋 Version Notes

Spring Boot 2.x

Standard property resolution behavior.

Spring Boot 3.x

Stricter handling of nested placeholders and relaxed binding.

🛡️ How to Prevent This Next Time

Always provide default values in @Value for non-critical properties: ${key:default}.