Quick revision
The short answer
A @Value field is null when Spring never injected it. The usual causes are that the object is not a Spring bean because it was created with new, that the field is static, that the value is read in the constructor before field injection has happened, or that the class is a BeanFactoryPostProcessor or another bean created too early for value injection. A placeholder that cannot be resolved does not give null: startup normally fails, unless a default was given.
What to remember
In this answer, we saw that @Value is filled by a bean post processor after the constructor of a Spring-managed bean has run. So the field stays null when the object was created with new or by another framework, when the field is static, when the value is read in the constructor, or when the bean is created too early, such as a BeanFactoryPostProcessor. A missing property normally fails startup instead of giving null, and reading fields through a CGLIB proxy is a less common trap. Constructor injection avoids most of these problems.
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.
A @Value field is null when Spring never injected it. The usual causes are that the object is not a Spring bean because it was created with new, that the field is static, that the value is read in the constructor before field injection has happened, or that the class is a BeanFactoryPostProcessor or another bean created too early for value injection. A placeholder that cannot be resolved does not give null: startup normally fails, unless a default was given.
Why this question is asked
A null @Value is one of the first configuration bugs most Spring developers meet, and it is confusing because the annotation is right there and the property exists in application.yml. Interviewers ask it because the causes all come from one idea: @Value is not magic attached to the field, it is work that Spring does on a bean at a specific moment of its life. Once we know when and on what Spring does that work, every cause follows. In this answer, we will recap how @Value gets injected, then walk through each cause with the broken code and the fix, and finish with a quick way to tell them apart.
1A Quick Recap of How @Value Gets Injected
Spring creates a bean in a fixed order. It first calls the constructor. Then a bean post processor, AutowiredAnnotationBeanPostProcessor, a helper Spring registers early in the context, looks for @Autowired and @Value fields and setter methods and fills them in. Only after that does Spring call initialisation callbacks such as @PostConstruct methods, and only then does other code get the bean.
Two things follow from this. Spring can only inject into objects it creates and manages, and it injects fields after the constructor has finished. Every cause of a null @Value is a case where one of these two conditions does not hold.
- Spring calls the constructorfields are still null here
- Post processor injects @Autowired and @Value fieldsplaceholders resolved from the Environment
- @PostConstruct methods runfields are set now
- Bean is handed to other beanssafe to use
4 steps in order. Play them, or step through them one at a time.
2Cause 1: The Object Is Not a Spring Bean
The most common cause is creating the object ourselves. Spring never sees an object made with new, so nothing injects its fields. The same happens with objects created by other frameworks, such as a JPA entity loaded by Hibernate, an object deserialized by Jackson, or a class instantiated by a library through reflection.
Notice that a primitive field shows 0.0 or 0 rather than null, which can hide the bug even longer. The fix is to get the object from Spring by injecting it, and to pass configuration values explicitly into objects that are not beans.
3Cause 2: The Field Is Static
Spring injects into instances, not classes, so @Value on a static field is ignored. Spring logs an informational message saying the annotation is not supported on static fields, but the field simply stays null.
People usually make the field static so a static utility method can use it. The better design is to make the utility a bean, or to pass the value as a parameter. Assigning a static field from a setter does work, but it couples the whole class to whichever context set it last and breaks tests that use different values.
4Cause 3: Using the Value in the Constructor
Field injection happens after the constructor. So code inside the constructor that reads an @Value field sees null, even though the field will be set a moment later.
The fix is to take the value as a constructor parameter, which also lets the field be final and makes the dependency visible in tests. If the work must stay in a method, a @PostConstruct method also sees the injected fields, but constructor injection is the clearer choice.
5Cause 4: The Bean Is Created Too Early
Some beans are created before AutowiredAnnotationBeanPostProcessor is ready. The classic example is a BeanFactoryPostProcessor, a bean that modifies bean definitions before ordinary beans are created. Spring must instantiate it very early, so @Value and @Autowired on it are not processed. A @Bean method that returns a BeanFactoryPostProcessor from a normal @Configuration class causes a similar problem for that configuration class, which is why Spring logs a hint to declare such methods static.
A related case is a bean that another early bean depends on, for example a bean injected into a BeanPostProcessor. Spring then creates it before all post processors are registered and logs a message that it is not eligible for getting processed by all BeanPostProcessors. Such a bean may miss injection and proxying. The fix is to read configuration through the Environment directly in those early beans, or to keep their dependencies to a minimum.
6What an Unresolved Placeholder Really Does
It is tempting to think a missing property gives null, but in Spring Boot it does not. If no property source contains the key and there is no default, startup fails with an IllegalArgumentException saying it could not resolve the placeholder. With a default, the default is used. So when a @Value field is null in a running application, the property is almost never the problem; the injection did not happen.
There is one more trap worth knowing: a proxy. When a class is proxied with CGLIB, for example because it has @Transactional methods, other beans hold the proxy, not the real object. The proxy is a generated subclass whose own fields are never injected. If code reads the field directly, or calls a final method that cannot be intercepted and so runs on the proxy, it sees null. Accessing the value through a normal public method of the bean avoids it.
| Symptom | Likely cause |
|---|---|
| Null everywhere in one object, fine in injected ones | Object created with new or by another framework |
| Null in a static field, message in the log | Static field |
| Null only inside the constructor | Read before field injection |
| Null in a post processor or its dependencies | Bean created too early |
| Null when read from another class or a final method | Reading fields through a CGLIB proxy |
| Application does not start | Missing property without a default |
7Follow-up questions
Why is constructor injection recommended for @Value?
Because the value is available as soon as the object exists, the field can be final, the dependency is visible to anyone creating the object in a test, and causes 2 and 3 cannot happen. It also works the same way with records and with @ConfigurationProperties constructor binding.
What happens in plain Spring Framework without Spring Boot when a placeholder is missing?
It depends on whether a placeholder configurer is registered. Without one, Spring injects the literal text ${key} rather than failing or giving null. With a PropertySourcesPlaceholderConfigurer, which Spring Boot always registers, an unresolvable placeholder fails by default, and we can change that with setIgnoreUnresolvablePlaceholders(true).
How can I check whether an object is a Spring bean at runtime?
Inject the ApplicationContext and call getBeansOfType for the class, or set a breakpoint in the constructor and look at the stack: a bean's constructor is called from Spring's bean factory classes, while a hand-made object's constructor is called from our own code.
8Conclusion
In this answer, we saw that @Value is filled by a bean post processor after the constructor of a Spring-managed bean has run. So the field stays null when the object was created with new or by another framework, when the field is static, when the value is read in the constructor, or when the bean is created too early, such as a BeanFactoryPostProcessor. A missing property normally fails startup instead of giving null, and reading fields through a CGLIB proxy is a less common trap. Constructor injection avoids most of these problems.
Open with
When a @Value field is null, I first remind myself that @Value is injected by a bean post processor after Spring has called the constructor, and only on beans Spring creates.
Then, if they want more
So the first thing I check is whether the object is a bean at all: if someone created it with new, or it is an entity or a Jackson object, nothing injects it. Second, I check whether the field is static, because Spring only injects instance fields and just logs a message.
Third, I check whether the value is used in the constructor, because at that point field injection has not happened yet; the fix is to take it as a constructor parameter, which also makes the field final.
Fourth, I look at whether the class is created too early, typically a BeanFactoryPostProcessor or something a BeanPostProcessor depends on; those do not get value injection, so I read the Environment directly there. I would also check whether the code reads the field through a CGLIB proxy, for example from a final method.
What I would not suspect first is the property itself: in Spring Boot an unresolvable placeholder fails startup unless there is a default, so a running application with a null field almost always means the injection did not happen.
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 "A @Value field is null at runtime. List the common causes.": https://scrivio-interview-library.netlify.app/spring-boot/spring-configuration/9bfafd7f59/