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.


6 thoughts on “Tedious Spring error message, and its solution”

  1. Thanks for pointing out the cause of this error. I necountered it in similar circumstances, the problem though was different: The Tomcat server I’d copied the file to hadn’t cleared its work folders properly so I deleted them and restarted Tomcat and the problem was solved. Still not sure why this class got loaded at all though.

  2. Thanks, you pointed me to the right direction!
    In my case the fix was to change tomcat config (server.xml) unpackWARs=”false” to unpackWARs=”true”.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s