Spring (from version 4) claims to support generic type injection and I'm trying to do something like this:
public abstract class AbstractControl<T extends IService> {
@Autowired
private T service;
protected T getService(){
return service;
}
public void setService(T service) {
this.service = service;
}
}
then an extension of this class:
public class FooControl extends AbstractControl<LoginService> {
}
but Spring is trying to inject IService. Is it possible to inject the inherited type?
Try moving the @Autowired into the subclass, like this:
public abstract class AbstractControl<T extends IService> {
private T service;
protected T getService(){
return service;
}
public void setService(T service) {
this.service = service;
}
}
And the subclass:
public class FooControl extends AbstractControl<LoginService> {
@Override
@Autowired
public void setService(LoginService service) {
this.service = service;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With