Tedious Spring error message, and its solution

This is a public information broadcast for the benefit of developers using Spring MVC with annotation-driven configuration.

I was a bit stumped earlier by this error on startup of my web application:

java.lang.IllegalStateException: Annotation-specified bean name ‘enterOrderNumberController’ for bean class [uk.ac.bham.ework.eb.controllers.EnterOrderNumberController] conflicts with existing, non-compatible bean definition of same name and class [uk.ac.bham.ework.eb.controllers.bookingoperations.EnterOrderNumberController]

followed by a lovely stack trace. The webapp had been running fine locally, but died as soon as I copied it across to the test server. Here is the explanation. Look carefully at those two class names in the first line again:

  • uk.ac.bham.ework.eb.controllers.EnterOrderNumberController
  • uk.ac.bham.ework.eb.controllers.bookingoperations.EnterOrderNumberController

Not the same, are they? I had been doing a little neatening-up, moving EnterOrderNumberController into a different package. On my local box, the IDE had kindly deleted the compiled version of uk.ac.bham.ework.eb.controllers.EnterOrderNumberController from WEB-INF/classes. On the test server, I had done an svn update and then just run the Ant build script, and my not-very-well-written build.xml had not cleaned up the debris from previous builds.

So I had two classes called EnterOrderNumberController in my classpath, and Spring was trying to instantiate both, but finding they both needed the same bean name, which wasn’t allowed. The solution was to get rid of the old, now-superfluous one.

The build script has now been modified.

Thank you for listening to this public information broadcast.