Wednesday, June 19, 2013

The importance of servlet-mapping

Ok, let's go ahead and set the stage here.  I've been trying to configure Spring and Jersey to play well together in Tomcat.  Specifically, I'm trying to use the latest and greatest of my dependencies - so, for now that means Spring 3.2.3-RELEASE, and Jersey 1.17.1, with Tomcat 7.0.21.

Now, I have everything configured correctly for Spring - I see that the beans are being created by the DefaultListableBeanFactory line in my Tomcat console.  Everything should be good.  I have double checked my web.xml, and I have the correct contextConfigLocation and ContextLoadListener in my it.  I've also changed my servlet to use com.sun.jersey.spi.spring.container.servlet.SpringServlet, which should allow Jersey to see all of my Spring beans. 

But, I still am getting the dreaded Null Pointer Exception, letting me know that my Jersey services sure aren't getting injected.  I've tried everything - changing annotations from @Component to @Service.  Setting the name of the @Component.  Creating unnecessary Interfaces.  Sleeping on it to make things magically make sense.  Nothing!

Then, I notice one thing - I have a servlet-mapping (which hasn't really seemed to do much to this point for some reason) that's url-pattern is /ws.  Well, I went ahead and changed that to end in /*, which allows it to do pattern matching instead of exact matching.  *Poof*!  Everything suddenly works.

Hope that helps someone else that runs into this issue.

No comments: