是否可以在动态类上自动装配字段?
使用工厂很棒,但它不允许我去@Autowire
田地。
public static Workflow factory(WorkflowEntity workflowEntity) {
try {
Class<?> clazz = Class.forName(workflowEntity.getClassName())
.asSubclass(Workflow.class);
Object workflowClass = clazz.getConstructor(WorkflowEntity.class).newInstance(workflowEntity);
return (Workflow) workflowClass;
} catch (Exception e) {
e.printStackTrace();
logger.severe("Unable to instantiate "+workflowEntity.getClassName()+" class: " + e.getLocalizedMessage());
}
return null;
}
是否可以这样做,但是以 Spring 处理自动装配字段的方式?