Reputation: 5763
I have three database cofinguration
How Can I automatic inject different db properties according to environment ?
By using xml with spring, I can use maven profiles and Resources filter feature to have this work done.
What 's the solution with guice?
Upvotes: 1
Views: 149
Reputation: 66273
In the simplest case you can use binder.bindConstant()
within your Module
like this:
bindConstant().annotatedWith(Names.named("user.name")).to(System.getProperty("user.name"));
You use this like this:
@Inject @Named("user.name")
private String userName;
How you set the system properties at the start of the program is up to you.
Another but similar way is the utility method cNames.bindProperties(Binder, Map<String, String>)
where you can set arbitrary properties in one go.
Upvotes: 1