I'm new to Spring and I have a question about how it works.
Why is the interface instantiated in Spring framework and not the class that implements it?
I have seen several tutorials and they all do the same but I can not understand why
The interface:
public interface ILoginServicio {
public String getLogin(String usuario, String contrasena);
public boolean getMultiSearchResult(DirContext dirContext, String searchFilter, String searchBase);
public boolean displayAttribute(String attrName, final Attributes attributes);
}
The class implementing the interface:
@Service
public class LoginServicioImpl implements ILoginServicio{
@Autowired
private Environment environment;
@Override
public String getLogin(String usuario, String contrasena) {
....
}
@Override
public boolean getMultiSearchResult(DirContext dirContext, String searchFilter, String searchBase) {
...
return flagActiveDirectory;
}
@Override
public boolean displayAttribute(String attrName, Attributes attributes) {
....
return flagActiveDirectory;
}
}
Restcontroller class where the bean is injected to:
@RestController
public class Login {
@Autowired
ILoginServicio iLoginServicio;
@RequestMapping("/login")
public Respuesta<String> login(@RequestBody UsuarioLogin user){
//.......
}
}