title: Guice: value of field annotated with @Named is null
body: <p>I have a class in which I declare my static constants:</p>
  
  <pre><code>public final class ConfigOptions {
      public static final String FILE_PATH_SERVER = "/home/user/me/somefile";
  }
  </code></pre>
  
  <p>Then I use Guice to bind it in my <code>ServletModule</code>:</p>
  
  <pre><code>public class MyServletModule extends ServletModule {
      bind(String.class).annotatedWith(Names.named("filePath"))
          .toInstance(ConfigOptions.FILE_PATH_SERVER);
  
      // Also tried
      // bindConstant().annotatedWith(Names.named("filePath")).to(ConfigOptions.FILE_PATH_SERVER)
  
      // ... other bindings
  }
  </code></pre>
  
  <p>My <code>GuiceServletContextListener</code>:</p>
  
  <pre><code>public class MyServletContextListener extends GuiceServletContextListener {
  
      @Override
      protected Injector getInjector() {
          return Guice.createInjector(new MyServletModule());
      }
  }
  </code></pre>
  
  <p>Finally, I try to use <code>filePath</code>:</p>
  
  <pre><code>public class MyClass {
  
      @Inject
      @Named("filePath")
      private String filePath;
  
      public MyClass() { ... }
  
      public void doSomething() {
          someotherThing.setFilePath(filePath);  // But filePath is null
      }
  }
  </code></pre>
  
  <p>I mostly follwed the method shown <a href="http://blog.japila.pl/2011/01/abstractmodule-bindconstant-inject-and-named-in-google-guice/" rel="nofollow">here</a> but not sure if I'm missing something.</p>
  
  <p>Additionally, I've made sure that the correct <code>import com.google.inject.name.Named</code> is imported.</p>