title: Get access to all spring beans of a given type
body: <p>I have a Spring application (Spring Batch not web application). In a test class, I want to grab access to all of my beans of a given type.  <br><br>
  I understand that in Spring you should generally use IOC and let the container inject your beans. However in this case, I want to loop through a variable number of beans that extend a given class (org.springframework.batch.item.database.JdbcCursorItemReader), and do something (want it to be a unit/integration test that just connects it to the database and reads 1 row, so we can confirm at test time that all of the JdbcCursorItemReader in the system have valid SQL and row mappers).</p>
  
  <p>Problem 1) I can only get beans one at a time. I can have my class <strong>implement BeanFactoryAware</strong> to get a reference to my beanfactory. Then I can do <strong>beanFactory.getBean("name");</strong> to get access to a single bean. How do I instead get ALL beans? I can loop through and drop the ones that aren't the class I want.. but somehow I need a list of all beans the beanfactory knows about or something.</p>
  
  <p>Problem 2) The bean I get back from the beanfactory is a proxy. If I try to cast and use my bean I get something like
  <strong>java.lang.ClassCastException: $Proxy0 cannot be cast to org.springframework.batch.item.database.JdbcCursorItemReader</strong></p>