Skip to content

Static variable set to null by @Value

My Constants File:

    public class Constants {
        public static String ROOT_DOMAIN;
        private void setRootDomain(String rootDomain) {
            ROOT_DOMAIN = rootDomain;


My Referring Class and Method:

public class MyServiceClass
        public void doSomething()
           System.out.println("Root is:" + Constants.ROOT_DOMAIN);

But Root Domain is coming as null

[update] My spring-master.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns=""

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">

        <property name="ignoreUnresolvablePlaceholders" value="true"/>
        <property name="ignoreResourceNotFound" value="true" />
        <property name="searchSystemEnvironment" value="true" />
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
    <context:component-scan base-package="">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>  
    <context:component-scan base-package="" />

    <!-- Application Context Provider -->
    <bean id="appContextProvider" class=""/>


And the ApplicationContextProvider class is as follows:

public class ApplicationContextProvider implements ApplicationContextAware {

     private static ApplicationContext context;

     public static ApplicationContext getApplicationContext() {
         return context;

     public void setApplicationContext(ApplicationContext ctx) {
         context = ctx;

So yes the files are in classpath


@Value() gets called on the initialization of the bean , the bean gets initialized on need not on the startup so you will not have the value unless the bean is initialized