How to bind String to variable in Guice?

Viewed 38679

I'm new to Guice and here is a naive question. I learned that we could bind String to a particular value through:

bind(String.class)
        .annotatedWith(Names.named("JDBC URL"))
        .toInstance("jdbc:mysql://localhost/pizza");

But what if I want to bind String to any possible characters?

Or I think it could be described this way:

How can I replace "new SomeClass(String strParameter)" with Guice?

4 Answers

I was able to inject a string through Named annotation.

@Provides
@Named("stage")
String stage() {
    return domain;
}

class SomeClass {
   @Inject
   @Named("stage")
   String stageName;
}
Related