PDA

View Full Version : Verifying bean classpath dependencies without instantiating



timmorrow
Dec 5th, 2006, 10:03 AM
The problem I'm trying to solve is to verify that the classpath provides all the classes needed by the beans in a set of XML files. I'd like to do this as often as possible (say as a unit test run during a build). An additional feature would be to verify bean references too.

I realize that unit tests shouldn't load Spring beans. But this is because the beans have dependencies (database, JMS, JNDI) that aren't available to unit tests.

This technique would be a special way of loading the spring beans without actually instantiating any of them. I did this once before using Spring 1.x by traversing the beans in a bean factory and manually verifying bean references. IIRC Spring verified the classes for me. However, I don't think I took care of all types of bean references like idref and the like.

I was hoping that perhaps with Spring 2.x there is perhaps a built-in method for doing this? For example, is there a way to make a BeanFactory be lazy, without having to set that property in the XML file itself?

Any suggestions would be appreciated,

Thanks,

Tim

reibai
Dec 5th, 2006, 11:20 AM
Why not do the following:

Create an integration test using org.springframework.test.AbstractDependencyInjecti onSpringContextTests (or something similar) to load up your xml files, but with an additional xml file that does mark all of the beans as lazy. You could then just iterate through all of the bean definitions from the supplied appContext (which won't instantiate them), checking the class via Class.forName(beanDefinition.getBeanClassName()), etc.

timmorrow
Dec 5th, 2006, 04:12 PM
Thanks for the suggestion.

I should probably try this out before responding... but I was under the impression the default-lazy-init setting is local to the bean file its defined in, as opposed to affecting the entire application context.

Anyway, I should give it a try.

Thanks,

Tim