title: Null pointer Exception when attempting to inject a configuration into static method using springboot framework
body: <p>I have a configuration file called <code>proxyconfig.java</code> that reads from a yaml file and injects it into <code>ProxyConfig.java</code> file. I need to use the properties from my config to inject it into Httputil class to set up a proxy but i'm getting a null pointer exception as it doesn't inject the properties host and port to set up the proxy. I'm using the StaticContextAccessor to access the proxy config class and get the host and port values. Please could someone assist in what i'm currently doing wrong?</p>
  
  <pre><code>@Configuration
  public class ProxyConfig {
     @Value("${proxy.host}")
     private String host;
  
     @Value("${proxy.port}")
     private int port;
  
     public int getPort() { return this.port; }
     public int getHost() { return this.host; }
  
  }
  </code></pre>
  
  <p>StaticContextAccessor class:</p>
  
  <pre><code>public class StaticContextAccessor {
      private static StaticContextAccessor instance;
  
      @Autowired
      private ApplicationContext applicationContext;
  
      @PostConstruct()
      public void registerInstance() {
        instance = this;
      }
  
      public static &lt;T&gt; T getBean(Class&lt;T&gt; clazz) {
        return instance.applicationContext.getBean(clazz);
      }
  }
  </code></pre>
  
  <p>My HttpUtil class:</p>
  
  <pre><code>public class Httputil {
       private static RequestConfig defaultRequestConfig = RequestConfig.custom()
         .setConnectTimeout(1000)
         .setSocketTimeout(10000)
         .setConnectionRequestTimeout(10000)
          // setting the proxy
          //causes null pointer as it cannot read host and port
         .setProxy(new HttpHost(StaticContextAccessor.getBean(ProxyConfig.class).getHost(), StaticContextAccessor.getBean(ProxyConfig.class).getPort())
      }
  </code></pre>