Nice Error Messages in Spring

Working through Chapter 2 of Spring: A Developer’s Notebook tonight, and I’m pleasantly surprised by Spring’s error messages. This is the first one I got after deploying one of the examples:

1
2
3
4
5
6
7
org.springframework.beans
.factory.BeanDefinitionStoreException:
Error registering bean with name 'viewResolver' defined in ServletContext resource
[/WEB-INF/rentABikeApp-servlet.xml]: Bean class [org.springframework.web.servlet
.view.InternalResourceViewResolvers] not found;
nested exception is java.lang.ClassNotFoundException: org.springframework.web
.servlet.view.InternalResourceViewResolvers

This points me to the file and the exact reference that is causing the problem just by reading the error message. I suppose a line number would be the only thing missing. Turns out I had an extra ‘s’ at the end of InternalResourceViewResolver. A quick fix and the next error message:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
org.springframework.beans.
factory.BeanCreationException:
Error creating bean with name
'editBikeForm' defined in ServletContext resource
[/WEB-INF/rentABikeApp-servlet.xml]:
Error setting property values;
nested exception is org.springframework.beans
.PropertyAccessExceptionsException:
PropertyAccessExceptionsException (1 errors);
 nested propertyAccessExceptions are: [org.springframework.beans
.TypeMismatchException:
Failed to convert property value
 of type [java.lang.String] to
required type [java.lang.Class] for property
 'commandClass';
nested exception is
java.lang.IllegalArgumentException:
Invalid class name: com.springBook.Bike]

This one is pretty obvious as well, whoops com.springbook not com.springBook. It’s nice that it points you to the errors right away. I’ve seen so many java open source packages that don’t point you at the real error relying too often on a simple stack trace.