title: Spring boot autowiring BeanCreationException for static field
body: <p>I am having an issue when I am autowiring my properties class.</p>
  
  <p>The following is my properties class which behaves fine when I autowire it in my @service class.</p>
  
  <pre><code>import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.cloud.context.config.annotation.RefreshScope;
  import org.springframework.core.env.Environment;
  import org.springframework.stereotype.Component;
  
  @Component
  @RefreshScope
  public class SMSHistoryProperties {
  
      @Autowired
      Environment env;
  
      /**
       * Return the property value associated with the given key, or null if the
       * key cannot be resolved.
       * 
       * @param propName
       * @return
       */ 
      public String getProperty(String propName){     
          return env.getProperty(propName);
      }
  </code></pre>
  
  <p>but when I autowire it in my SQLConstants class (which only has static constant variables) I am getting an exception.</p>
  
  <pre><code>import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Component;
  
  import com.vzw.onem.search.properties.SMSHistoryProperties;
  
  @Component
  public class SQLConstants {
  
      @Autowired
      private static SMSHistoryProperties prop;
  
      //~ Static fields/initializers ------------------------------------------
  
      private static final String SMS_SCHEMA = prop.getProperty("sms.schema");
  </code></pre>
  
  <hr>
  
  <p>The exception I get is the following:</p>
  
  <pre><code>org.springframework.beans.factory.BeanCreationException: Error
  creating bean with name 'SQLConstants' defined in file
  [...\SQLConstants.class]: Instantiation of bean failed; nested
  exception is org.springframework.beans.BeanInstantiationException:
  Failed to instantiate [com.search.constants.SQLConstants]: Constructor
  threw exception; nested exception is java.lang.NullPointerException
  </code></pre>
  
  <hr>
  
  <p>EDIT:</p>
  
  <p>I took the static final reference out but I am still getting a null pointer exception. </p>
  
  <pre><code>@Autowired
  private SMSHistoryProperties prop;
  
  private String BATCH_SMS_SQL = "SELECT ACK_CODE FROM "
              + prop.getProperty("sms.schema");
  </code></pre>
  
  <p>The <code>nullpointer</code> is occurring on <code>prop.getProperty("sms.schema")</code>.</p>
  
  <blockquote>
    <p>org.springframework.beans.factory.UnsatisfiedDependencyException:
    Error creating bean with name 'SMSController': Unsatisfied dependency
    expressed through field 'smsBuilder'; nested exception is
    org.springframework.beans.factory.UnsatisfiedDependencyException:
    Error creating bean with name 'SMSBuilder': Unsatisfied dependency
    expressed through field 'searchHelper'; nested exception is
    org.springframework.beans.factory.UnsatisfiedDependencyException:
    Error creating bean with name 'smsJdbcSearchHelper': Unsatisfied
    dependency expressed through field 'cccDao'; nested exception is
    org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name 'smsSearchDAOImpl' defined in file
    [..\SmsSearchDAOImpl.class]: Instantiation of bean failed; nested
    exception is org.springframework.beans.BeanInstantiationException:
    Failed to instantiate [com.vzw.onem.search.dao.impl.SmsSearchDAOImpl]:
    Constructor threw exception; nested exception is
    java.lang.NullPointerException</p>
  </blockquote>