Wäre es technisch eine gute und akzeptable Methode, erforderliche Abhängigkeiten mit einem Interceptor
-Typ zu injizieren. Zum Beispiel:Abhängigkeiten mit einem Interceptor einsperren
public @interface Inject {
public Class thisType();
}
public class InjectionInterceptor implements HandlerInterceptor {
@Override
public bool preHandle(HttpServletRequest hsr, HttpServletResponse hsr1, Object o) {
HandlerMethod handlerMethod = (HandlerMethod) o;
Class type = handlerMethod.getBeanType();
Annotation[] annotations = type.getAnnotationsByType(Inject.class);
for(Annotation annotation: annotations){
Inject inject = (inject) annotation;
for(Field field :type.getDeclaredFields()){
if(field.getType().equals(inject.thisType())){
field.setAccessible(true);
field.set(handlerMethod.getBean(), Services.find(inject.thisType()));
}
}
....
return true;
}
...
}
Was würden wir mit dieser Art von Dependency Injection erreichen? –
Und das willst du im Frühling machen, wo du schon DI hast? Warum? Du weißt, dass du '@ Autowired' richtig benutzen kannst? – Antoniossss
@Antoniossss: Autowired ist so nutzlos, wie können Sie sagen, auf welchen Typ eine Schnittstelle gebunden werden muss und was, wenn es Singleton oder instanziiert einmal pro Sitzung sein muss. – Arrrr