I'm looking for the DI container to deduce this information from the bytecode rather than me having to supply it in XML.
I don't believe Spring has such functionality. If you could annotate your constructor like so
@Autowired
public TaskController(ITaskRepository tasks) { ... }
and there was only one bean that implements ITaskRepository
in the context, then Spring could figure it out, but you'll need the annotation.
Correct me if I misunderstood your question.
If you don't have control of the class to add annotations, you can still use the <bean>
<constructor-arg>
element to reference and use another bean when invoking the constructor.
<bean id="taskRepository" class="com.some.TaskRepositoryImpl" />
<bean id="taskController" class="com.some.TaskController">
<constructor-arg ref="taskRepository" />
</bean>
Alternatively, with Java configuration
@Bean
public ITaskRepository taskRepository() {
return new TaskRepositoryImpl();
}
@Bean
public TaskController taskController() {
return new TaskController(taskRepository());
}