Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8284965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:18:08+00:00 2026-06-08T11:18:08+00:00

I have a usecase for which I cannot use the Qualifier annotation (atleast according

  • 0

I have a usecase for which I cannot use the Qualifier annotation (atleast according to my understanding) but I still need to resolve between two beans for Autowire. I cannot use the Qualifier because I dont know which implementation of FooBar will be used inside class Foo. Here is the setup I have:

class Foo
{
    @Autowired
    private FooBar a;
    public Foo(FooBar aa) {a = aa; }
}

interface FooBar
{}

class FooBarA implements FooBar
{}

class FooBarB implements FooBar
{}

spring config:

<bean id="beanA" class="FooBarA"/>
<bean id="beanB" class="FooBarB"/>

<bean id="bean1" class="Foo">
    <constructor-arg><ref bean="beanA"/></constructor-arg>
</bean>

<bean id="bean2" class="Foo">
    <constructor-arg><ref bean="beanB"/></constructor-arg>
</bean>

This throws an error saying it cannot resolve the bean for the variable “a” in class “Foo” because there are two beans (beanA and beanB) even though I have explicitly specified which derivation of FooBar to use in each case of bean1 and bean2.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:18:09+00:00Added an answer on June 8, 2026 at 11:18 am

    I believe the constructor injection should look like this:

    <constructor-arg>
        <ref bean="beanA"/>
    </constructor-arg>
    

    Or even just

    <constructor-arg ref="beanA" />
    

    Also move the @Autowired annotation from FooBar in Foo to the constructor since you’re using constructor injection.

    Alternatively, you could use field injection by doing this:

    <bean id="bean1" class="Foo">
        <property name="a" ref="beanA" />
    </bean>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a use case in which I need to first show the value
This might not have a major usecase in projects, but I was just trying
I have a use case where I need to call a (non-static) method in
I have a use case where if a number lies between 0-10 it should
I have a use case where I only need to store certain fields to
Here's a use case: I have a desktop application (built using Eclipse RCP) which
For a school assignment, we have to make a Usecase diagram. But the documentation
I have a fairly simple requirement for a query API which I need to
I have the following usecase: I have a java project (myProj) which uses a
I have found the DTrace intriguing but have personally failed to see a use-case

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.