I want to have a Spring component with prototype scope instantiated as needed at runtime, using pure Java implementation (Spring JavaConfig annotations). Say i have a bean as follows:
@Component
@Scope("prototype")
public class MyTask {
@Autowired
Field myField;
runTask() {...}
}
I want to be able to do the following:
MyTask task = //instantiate new task
task.runTask();
I can always use:
ApplicationContext.getBean(MyTask.class)
But that would completely contradict the notion of inversion of control. Can this be done with JavaConfig pure Java implementation (i.e. no use of xml files)?
UPDATE:
To be more specific, I'm looking for a way that will be similar to the xml based solution of lookup-method factory that is explained in this SO post