I have a interface as
public interface ConfFileLoader {
public Map<String, Object> getResultMap() throws SecurityException, IOException;
}
and a class that imlements it as
public class ConfYamlLoader implements ConfFileLoader{
@Override
public Map<String, Object> getResultMap() throws SecurityException, IOException {
}
}
and has a injector class as
public class AppInjector extends AbstractModule {
@Override
public void configure() {
bind(ConfFileLoader.class).to(ConfYamlLoader.class);
}
}
Now the problem is i have a class as
public class TI {
@Inject
private ConfFileLoader confFileLoader;
public void test(){
System.out.println("yeah tesrintY>>>>>>>>>>>>>>>>>>>"+confFileLoader);
}
}
and it gives exception as
Exception in thread "main" com.google.inject.ConfigurationException: Guice configuration errors:
1) No implementation for com.exzeo.conf.ConfFileLoader was bound.
while locating com.exzeo.conf.ConfFileLoader
for field at com.exzeo.automate.HCPCI.TI.confFileLoader(TI.java:10)
while locating com.exzeo.automate.HCPCI.TI
but when i do @ConfYamlLoader it works fine as
public class TI {
@Inject
private ConfYamlLoader confFileLoader;
public void test(){
System.out.println("yeah tesrintY>>>>>>>>>>>>>>>>>>>"+confFileLoader);
}
}
This above class works fine
So on investigation I found when I add @implemetedby on ConfFileLoader it works fine as
@ImplementedBy(ConfYamlLoader.class)
public interface ConfFileLoader {
public Map<String, Object> getResultMap() throws SecurityException, IOException;
}
I can't understand this behaviour that why i need to do @ImplementedBy if I am already binding it in binding module. As I per my understanding @implementedby is equavlane to bind().
Let me know if I am missing anything and I am using guice version 3
AppInjectorinstance toGuice.createInjector(). - Vladimir Matveevguicex.ConfYamlLoader@5dbc26eewhentest()method is called. - Vladimir Matveev