Tim Cooke wrote:Autowired isn't the right solution for this use case. In fact, your example given will fail to start as Spring will complain that it doesn't know which implementation of Vehicle it should inject.
You will need to write some code that will recognise the user input and create the correct implementation of Vehicle. The Factory Pattern might be a suitable approach to take here.
yes right now it will fail. but if i have configured all the beans in spring config file spring container has to create the instances of the beans. if i use factory pattern to create the objects based on the data passed from
ui then i think there is no use of using spring for this use case. i need to do it using features of spring only. that's why i had to ask if there is any way in spring to achieve this use case.