title: Spring: bean conflict with existing non-compatible bean
body: <p>Our project uses spring 2.5.5 and Tomcat. I have just migrated tomcat from 5.5 to 7. But when tomcat loads webapp context, we get this exception . 
  It seems spring scanned all the same components at least twice. Has anybody met this exception before?</p>
  
  <pre><code>Aug 16, 2012 1:54:36 PM org.apache.catalina.core.ApplicationContext log
  INFO: Initializing Spring root WebApplicationContext
  Aug 16, 2012 1:54:36 PM org.apache.catalina.core.StandardContext listenerStart
  SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
  org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [spring-configuration/application-context.xml]; nested exception is java.lang.IllegalStateException: Annotation-specified bean name 'observerLockMonitor' for bean class [aaa.aaa.ObserverLockMonitor] conflicts with existing, non-compatible bean definition of same name and class[aaa.aaa.ObserverLockMonitor]
  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:420)
  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:310)
  at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
  at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
  at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
  at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124)
  at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:92)
  at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:123)
  at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:423)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:353)
  at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
  at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
  at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
  at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
  at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
  at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
  at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
  at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
  at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618)
  at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:963)
  at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1600)
  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
  at java.util.concurrent.FutureTask.run(FutureTask.java:138)
  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
  at java.lang.Thread.run(Thread.java:662)
  Caused by: java.lang.IllegalStateException: Annotation-specified bean name 'observerLockMonitor' for bean class [aaa.aaa.ObserverLockMonitor]conflicts with existing, non-compatible bean definition of same name and class [aaa.aaa.ObserverLockMonitor]
  at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.checkCandidate(ClassPathBeanDefinitionScanner.java:267)
  at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:208)
  at org.springframework.context.annotation.ComponentScanBeanDefinitionParser.parse(ComponentScanBeanDefinitionParser.java:85)
  at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:69)
  at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1255)
  at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1245)
  at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135)
  at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92)
  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:507)
  at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:398)
  ... 27 more
  </code></pre>
  
  <p>The web.xml under WEB-INF is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app id="WebApp_ID" version="2.4"
      xmlns="http://java.sun.com/xml/ns/j2ee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;
              classpath*:spring-configuration/*.xml; 
              classpath*:spring-configuration/${apollo.realm}/${apollo.domain}/*.xml; 
              classpath*:spring-configuration/${apollo.realm}/*.xml  
          &lt;/param-value&gt;
  
      &lt;/context-param&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;
              org.springframework.web.context.ContextLoaderListener
          &lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;rds-eventProcessor&lt;/servlet-name&gt;
          &lt;servlet-class&gt;
              org.springframework.web.servlet.DispatcherServlet
          &lt;/servlet-class&gt;
          &lt;load-on-startup&gt;2&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;rds-eventProcessor&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;!-- 
      &lt;servlet&gt;
          &lt;servlet-name&gt;ping&lt;/servlet-name&gt;
          &lt;servlet-class&gt;
              amazon.rds.processor.utils.VipHealthCheck
          &lt;/servlet-class&gt;
          &lt;load-on-startup&gt;2&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;ping&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/ping/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      --&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>One of xml under classpath is application-context.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:context="http://www.springframework.org/schema/context"
         xmlns:tx="http://www.springframework.org/schema/tx"
         xmlns:p="http://www.springframework.org/schema/p"
         xmlns:aop="http://www.springframework.org/schema/aop"
         xsi:schemaLocation="http://www.springframework.org/schema/beans
                             http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                             http://www.springframework.org/schema/aop
                             http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
                             http://www.springframework.org/schema/context
                             http://www.springframework.org/schema/context/spring-context-2.5.xsd
                             http://www.springframework.org/schema/tx 
                             http://www.springframework.org/schema/tx/spring-tx-2.5.xsd "
         default-destroy-method="shutdown"&gt;
  
    &lt;context:annotation-config /&gt;
  
  
      &lt;context:component-scan base-package="aaa.aaa" /&gt;  
      &lt;context:component-scan base-package="bbb.bbb" /&gt;  
      &lt;context:component-scan base-package="ccc.ccc" /&gt;
  
  ...... here we have some other beans that are defined manually.
  &lt;/beans&gt;
  </code></pre>
  
  <p>The beans definition is :</p>
  
  <pre><code>@Component
  public class ObserverLockMonitor implements RDSAlfSessionDroppedListener {
      public interface RDSAlfSessionStartedListener {
          public void sessionStarted(AlfConnection alfConnection);
      }
  
      private static EventLog log = EventLogFactory.getEventLog(ObserverLockMonitor.class);
  
      private final RDSAlfConnectionFactory alfConnectionFactory;
      private final List&lt;RDSAlfSessionStartedListener&gt; sessionStartedListeners;
  
      /**
       * Timestamp of the last time we had a valid connection to alf...
       */
      private Long timeOfLastSeenAlfConnection = System.currentTimeMillis();
  
      private AlfConnection alfConnection;
  
      @Autowired
      public ObserverLockMonitor(RDSAlfConnectionFactory alfConnectionFactory, List&lt;RDSAlfSessionStartedListener&gt; sessionStartedListeners) {
          this.alfConnectionFactory = alfConnectionFactory;
          this.sessionStartedListeners = sessionStartedListeners;
      }
  </code></pre>
  
  <p>Any hints or pointers would be appreciated.
  Thanks.</p>