I have trouble finding a better headline, so forgive me please.
I basically have two classes, a service similar to this:
@Service
public class CharacterService {
@Autowired
private SimpMessagingTemplate websocket;
@Autowired
ArtifactsClient artifactsClient;
public void bringWoodToBank(String characterName) {
....
new DepositTask(character, deposit, artifactsClient, websocket, this);
}
}
and
public class DepositTask implements Task {
Logger log = LoggerFactory.getLogger(DepositTask.class);
private final ArtifactsClient artifactsClient;
private final SimpMessagingTemplate websocket;
private final CharacterService characterService;
private de.sveri.artifactsmmo.entities.Character character;
private Deposit deposit;
public DepositTask(de.sveri.artifactsmmo.entities.Character character, Deposit deposit,
ArtifactsClient artifactsClient, SimpMessagingTemplate websocket, CharacterService characterService) {
this.character = character;
this.deposit = deposit;
this.artifactsClient = artifactsClient;
this.websocket = websocket;
this.characterService = characterService;
}
}
As you can see, I am passing in two autowired services into DepositTask
. I am unable to make DepositTask
itself a @Service, as I need to pass in different parameters, that are available during runtime only.
Is there a spring / boot pattern, that allows me to autowire the services in DepositTask
itself or a different one, that enables me to mix and match constructor parameters, so that I can pass in injectable parameters and non injectable parameters?