4 Replies Latest reply on Jan 13, 2011 6:41 AM by Thorbjørn Andersen

    Want to access configuration strings with "@Inject @Named("server.username") String username;"

    Thorbjørn Andersen Newbie

      I have found that it is possible with Guice with JSR-330 to register a Map<String,String> so that


         @Inject @Named("server.username") String username; 


      injects the String value from said map registered under the key server.username.  Other keys given to @Named would result in the corresponding values being injected.


      To do this I loop over this snippet:


      bindConstant().annotatedWith(Names.named(key)).to(value);


      for each key,value pair in the configuration module.


      I want to be able to do the same thing with CDI in GlassFish 3.0.1, preferably in beans.xml, but I cannot figure out how to specify it.  I even asked this question on StackOverflow - http://stackoverflow.com/questions/4087766/how-to-inject-string-constants-easily-with-weld - but without success.


      Can it be done?  If so, how?


      Thanks!


      /Thorbjørn