Just starting to dig into Spring in Action. So far so good until I run into the first example. It’s just a Hello World style example so what could go wrong?
First issue crops up when I notice the following line:
BeanFactory factory = new XmlBeanFactory(new FileInputStream("hello.xml"));
IntelliJ just keeps barking at me that the constructor for
1
|
XmlBeanFactory
|
can only take a
1
|
org.springframework.core.io.FileSystemResource
|
. Digging through the APIs I find that since I’m using Spring 1.2.2, this has changed since the book’s printing. At least there’s a reference to it in Manning’s forums for the book. And they mention in the book that the examples are for 1.1.3.
After that I do a very dumb thing. I setup a simple unit test to invoke the HelloWorld method. So far so good. I run the test:
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory (long stack trace follows)
OK, so I assume I’ve just screwed up my path to the hello.xml file. That would be the bonehead move that costs me 45 minutes. Somehow I had it in my head that all the dependent libraries must be wrapped up in the spring.jar. After lots of red bars, I finally try importing
1
|
org.apache.commons.logging
|
. Of course IntelliJ can’t find it. A simple addition to my
1
|
lib
|
directory and my classpath and BooYa green bar. I sleep a lot better with green bars.