Issue
I am new using dependency injection. Can anyone tell me how to configure a servlet to inject a string URI pointing to a file? The method signature is the following:
@Inject
public void setCar(String value)
{
CarUri =value;
}
Solution
You can try injecting @Named
fields
// inside module
@Provides
@Named("CarURI")
public String carURI() {
return "URI";
}
@Inject
public void setCar(@Named("CarURI") String value) {
CarUri = value;
}
example:
- https://www.tutorialspoint.com/guice/guice_field_injection.htm
- https://www.tutorialspoint.com/guice/guice_method_injection.htm
Answered By - sampath.xyz
Answer Checked By - David Marino (JavaFixing Volunteer)