More a matter of curiosity: why do you bind the Properties instances
rather than the properties themselves?
I mean, instead of retrieving values from Proeprties, you could inject
properties values, kind of
class RestClient
{
@Inject @Named( "server.username" ) usr;
@Inject @Named( "server.password" ) pwd;
}
I could suggest you to try the Rocoto[1] extension to simplify
configuration bindings - not just because I maintain it! - it also
support variables interpolation.
HTH,
-Simo
[1] http://99soft.github.com/rocoto/
http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/
On Wed, Feb 29, 2012 at 11:01 AM, Gambo <[email protected]> wrote:
> Hi there,
>
> I am binding my property files with a provider. Now I have round about
> 3 different property files like: standard.properties,
> config.properties etc.
>
> Is there a more elegant way to have only one provider for all property
> files instead writing for each property file one provider?
>
> Code:
>
> bind(Properties.class).annotatedWith(Names.named("config")).toProvider(ConfigPropertiesProvider.class).in(Scopes.SINGLETON);
>
>
> static class ConfigPropertiesProvider implements Provider<Properties>
> {
>
> private Logger log =
> Logger.getLogger(ConfigPropertiesProvider.class);
>
> public Properties get() {
> return loadProperties();
> }
>
> private Properties loadProperties() {
> Properties prop =
> PropertiesUtil.loadProperties("config.properties");
> if(prop == null){
> log.error("config.properties not found");
> }
> return prop;
> }
> }
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-guice?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en.