Spring configuration in Java - Create and use 2 beans of same class NOT using Autowired
<p>I know the question of how to create and use two Spring beans of the same type has been answered before, and I've read a little bit about @Qualifier, and @Resource, but all the answers I've seen are in the context of autowiring.  In my case the place I'm trying to use the bean is in another part of the config file(s), so I'm not sure which parts of the solution apply.  I've also got a case were we're doing config in multiple ways (xml config files, and a java file with the @Configuration annotation.    Here's what the code looks like</p>

<pre><code>import com.this.that.AuthProvider;
@Configuration
...
    @Bean
    public AuthProvider buildAuthProvider() {
        return new AuthProvider(someotherbean);
    }

    @Bean
    public MyConnectionManager buildMyConnectionManager(AuthProvider authProvider) {
        return new MyConnectionManager(authProvider);
    }
    ...
</code></pre>

<p>another spring config xml file imported into application-config.xml</p>

<pre><code>  &lt;bean id="MyAuthProvider" class="com.this.that.AuthProvider"&gt;
    &lt;constructor-arg type="java.lang.String" ref="somedifferentbean" /&gt;
  &lt;/bean&gt;

  &lt;bean id="MyClient" class="com.that.this.MyClient"&gt;
    &lt;constructor-arg type="com.this.that.AuthProvider"
      ref="MyAuthProvider" /&gt;
  &lt;/bean&gt;
</code></pre>

<p>When I do this there's an error trying to create MyConnectionManager in the Java configuration file.  The error is on the the constructor arg with the following info )
org.springframework.beans.factory.UnsatisfiedDependencyException .. (excpected single bean but found 2: MyAuthProvider, buildMyConnectionManager())</p>

<p>I also see another bean in here that refers to the AuthProvider class, but instead of just specifying it as an argument into the bean constructor it uses a parameterless constructor and creates a new AuthProvider using the 'buildAuthProvider()' method.  I dont' see any complaint about that or the bean created in the xml file, but I'm not sure if this error is just masking the others.</p>

<p>Can someone help me figure out how to have these two separate beans?  They get created with a different value passed to their constructor, so I can't re-use the same bean in this case.</p>