I am trying to implement a strategy pattern with Enum, but I need Service to handle each of my task. I tried to @Autowired a service into Enum but it doesn't work. I have searched a bit for "How to inject bean into enum" and there comes an answer(but it looks not elegant for me ).
I am now hesitate to continue because I don't know if this is a good way to go. Do we have batter design for this kind of requirement?
public enum TaskType {
CREATE_MATERIAL{
@Override
public void handleTask(ScheduledEvent scheduledEvent) {
service.createMaterial(scheduledEvent);
}
};
@Autowired
private static AService service;
public abstract void handleTask(ScheduledEvent scheduledEvent);
}