-
1. Re: Want to access configuration strings with "@Inject @Named("server.username") String username;"
ravn.thorbjoern.gmail.com Nov 25, 2010 9:15 AM (in response to ravn.thorbjoern.gmail.com)Just in case.
Based on comments about being difficult to unit test, it would be fine with a setter on the bean:
@Inject
public void setUser(@Named("server.user") String user) {
this.user = user;
}(this one referencing
server.user
instead).Thanks.
-
2. Re: Want to access configuration strings with "@Inject @Named("server.username") String username;"
ravn.thorbjoern.gmail.com Jan 11, 2011 9:13 AM (in response to ravn.thorbjoern.gmail.com)This question is still relevant for us. Is there anybody who has a good suggestion for solving this?
(Having a Named on a String)
Thanks
/Thorbjørn
-
3. Re: Want to access configuration strings with "@Inject @Named("server.username") String username;"
nickarls Jan 12, 2011 1:55 AM (in response to ravn.thorbjoern.gmail.com)Hmm. Without giving it too much thought, perhaps it would be an idea to have another annotation for it altogether, something like @Config(
foo.bar
) and then you could have a producer that would run thefoo.bar
through EL. -
4. Re: Want to access configuration strings with "@Inject @Named("server.username") String username;"
ravn.thorbjoern.gmail.com Jan 13, 2011 6:41 AM (in response to ravn.thorbjoern.gmail.com)I've now found that Gavin showed a way to do this with a class with public fields in http://relation.to/Bloggers/WritingAPropertiesFileInJava giving the syntax I want.
My problem is that the key-value pairs are determined at runtime, so I cannot do this (unless I do some VERY nasty
hey Weld, here is a class I just made for you
).Can this be done with a Map<String, String>?