๐Ÿ”ด 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;

๐Ÿ› ๏ธ 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.

๐Ÿง  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 Prevent This Next Time

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

Course Search
Search across all chapters & stages
๐Ÿ“–

Search the course

Type any topic โ€” branching, stash, rebase, hooks โ€” and jump straight to that chapter.

merge branchesgit stashundo commitrebase