Call me lazy or crazy, but I have never really taken the time to look at everything that the Spring Framework can provide. I read an interesting web page the other day, complaining about the size of different Java frameworks. The author ranked Spring as the number one in “Complexity Pain” with over 2,400 classes. If you think about it, that is really amazing . Out of curiosity, I decided to look at the JavaDoc index for the Core Spring framework. It is actually quite impressive or quite paralyzingly!
Sometime back, I discovered something in Spring that I doubt is all that well known, but probably very useful to the average Java project, the Spring Util package. I once worked with a developer who liked to put guard statements inside all of his methods. He created his own assertion class that would look for null values or null parameters, and create informative exceptions when the method was used incorrectly (the guard was true). It was a little more helpful than the basic null pointer exception and much more convenient than adding a bunch of “if” blocks. While I was not accustomed to this programming style, I ultimately became more accepting of this practice. One day when I was creating a jUnit test, I accidentally discovered the Spring Util Assert class. The Spring Assert class had many more guard options than the one we used and the additional benefit of not being in our code base! Code is a liability… as one of my friends likes to say!
I would highly recommend that anyone using Spring become familiar with the classes in the Util package. I was actually quite surprised by the variety of support; from Java 5 annotations, collection utilities, numeric conversions, to the copying of files and many more. If you really think about it, the large number of support classes should not be all that surprising. Developers always seem to need these type of classes when building non-trivial software. Obviously, the more interesting and valuable Spring classes (the reason you would actually want to use the Spring Framework!) required these reusable utility classes to provide the overall functionality. So, why don’t we take advantage of them too?