title: ConflictingBeanDefinitionException : Same class name, different package
body: <p>I have a dao in one package:</p>
  
  <pre><code>package com.mypackage.dao;
  
  @Repository
  public class MyDao {
  // some code here
  }
  </code></pre>
  
  <p>I have another dao with same class name in a sub package:</p>
  
  <pre><code>package com.mypackage.one.dao;
  
  @Repository
  public class MyDao {
  // some other code here
  }
  </code></pre>
  
  <p>I have third class where I am trying to inject the bean using autowiring:</p>
  
  <pre><code>import com.mypackage.one.dao;
  
  public class TestClass{
  
  @Autowired
  private MyDao myDao;
  
  }
  </code></pre>
  
  <p>On deployment, I get the following error:</p>
  
  <pre><code>Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'myDao' for bean class [com.mypackage.dao.MyDao] conflicts with existing, non-compatible bean definition of same name and class [com.mypackage.one.dao.MyDao]
  </code></pre>
  
  <p>My applicationContext.xml has:</p>
  
  <pre><code>&lt;context:component-scan base-package="com.mypackage.dao"/&gt;
  &lt;context:component-scan base-package="com.mypackage.one.dao"/&gt;
  </code></pre>
  
  <p>I can not rename the classes as its a legacy application. </p>
  
  <p>What is the solution for this ? </p>
  
  <p>I tried using qualifier, but that is not working. </p>
  
  <p>Added below line:</p>
  
  <pre><code>&lt;bean id="oneMyDao" class="com.mypackage.one.dao.MyDao" /&gt;
  </code></pre>
  
  <p>And changed autowiring to:</p>
  
  <pre><code>@Autowired
  @Qualifier("oneMyDao")
  private MyDao myDao;
  </code></pre>
  
  <p>But it still throws the same error. </p>