I have a spring context file with several beans of type defined.
If the input to my program is “help” then I would like to display the bean names from the context file, so that the user can pick a particular bean and give it as input. The program would instantiate the bean with that name and perform some logic.
I am not able to query the list of bean names from a particular context file.
I don’t want to use a properties file to store the bean names as I am already using spring context files. Is there a better way to do this ?
I have a spring context file with several beans of type defined. If the
Share
Spring’s BeanFactory has got a method called
String[] getBeanDefinitionNames(). See Javadoc here. You can iterate through the returned list and show them to the user. then you can do a getBean call on the chosen bean name to run the logic.