title: How can I get a list of instantiated beans from Spring?
body: <p>I have several beans in my Spring context that have state, so I'd like to reset that state before/after unit tests.</p>
  
  <p>My idea was to add a method to a helper class which just goes through all beans in the Spring context, checks for methods that are annotated with <code>@Before</code> or <code>@After</code> and invoke them.</p>
  
  <p>How do I get a list of <strong>instantiated</strong> beans from the <code>ApplicationContext</code>?</p>
  
  <p>Note: Solutions which simply iterate over all defined beans are useless because I have many lazy beans and some of them must not be instantiated because that would fail for some tests (i.e. I have a beans that need a <code>java.sql.DataSource</code> but the tests work because they don't need that bean).</p>