Prezados é de meu conhecimento que desde que se anote um bean com @Component consigo injetar esse bean em outro via construtor.
Porém, gostaria de saber se há como pegar uma instancia, manualmente, algo como fazemos no Spring, através do context.
applicationContext.getBean(um type ou string aqui);
Explico o motivo: tenho um aspecto que pega beans gerenciados pelo Spring, porém os @Component do vraptor não estão neste contexto. Algo como:
public aspect DependencyResolver implements ApplicationContextAware {
private ApplicationContext applicationContext;
public void setApplicationContext(final ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
before(Object target) : get(@ResolveDependency * *) && target(target) {
try {
final Field field = target.getClass().getDeclaredField(thisJoinPoint.getSignature().getName());
field.setAccessible(true);
if (field.get(target) == null)
field.set(target, applicationContext.getBean(field.getType())); // COLOCARIA AQUI BEANS VINDOS DO VRAPTOR
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
grande abrasssss
(ou pq eu não li isso antes rsrs)