Maybe you can try injecting a Map<string, string> containing all the properties so you can figure it out from there (or if you can, figure it out earlier by choosing modules / bindings).
One hack that might work, if you can't live with the above, would be to use module overrides; so you would bind default values in one module and then you Modules.override those with the module that loads the properties file. Not sure why you'd prefer that though. Hope this helps, Robbie On Tue, Mar 24, 2009 at 9:11 PM, Martin <[email protected]> wrote: > > Hi All, > > I'm using Guice 2.0 to inject a class with values from a properties > file using the @Named annotation with Names.bindProperties() as well > as static injection using binder.requestStaticInjection() to wire > Guice. > > As an example my static class "Properties" with property keys contains > inject bindings as follows > > private static final String DEFAULT_COMPONENT_VERSION = > "2.0"; > > @Inject(optional = true) > @Named("version") > public static String PROP_COMPONENT_VERSION = > DEFAULT_COMPONENT_VERSION; > > The problem I am having is with exceptions. If I don't use > (optional=true) and my property is not defined inside the properties > file, Guice will throw a CreationException. I've been trying to catch > this exception around binder.requestStaticInject() without success > since a exception is throw within the Properties file. > > I would like to know how i can accomplish the continuation of the > program flow and simple notify the user on start-up using log("using " > +DEFAULT_COMPONENT_VERSION) instead of a CreationException that Guice > throws which halts everything. > > With (optional=true) i never actually know if the Guice bindings fail > or not. If they do then Guice just ignores and continues. > > Thanks, > Martin > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
