I have the following code:
@Component public class MainBean { @Autowired private MyTask myTask @Autowired private TaskScheduler taskScheduler public void start() { String str = "Print something to console"; //somehow call constructor and pass str argument?? taskScheduler.execute(myTask); } } @Component public class MyTask implements Runnable { private String str; @Autowired public MyTask(String str) { this.str = str; } @Override public void run() { System.out.println(str); } } I want to call MyTask and pass the str argument to the constructor. How can I do this? I cant find any good examples anywhere.