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 7919079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:44:19+00:00 2026-06-03T15:44:19+00:00

Background: I have a Spring 2.5/Java/Tomcat application. There is the following bean, which is

  • 0

Background:

I have a Spring 2.5/Java/Tomcat application. There is the following bean, which is used throughout the application in many places

public class HibernateDeviceDao implements DeviceDao

and the following bean which is new:

public class JdbcDeviceDao implements DeviceDao

The first bean is configured so (all beans in the package are included)

<context:component-scan base-package="com.initech.service.dao.hibernate" />

The second (new) bean is configured separately

<bean id="jdbcDeviceDao" class="com.initech.service.dao.jdbc.JdbcDeviceDao">
    <property name="dataSource" ref="jdbcDataSource">
</bean>

This results (of course) in an exception when starting the server:

nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.sevenp.mobile.samplemgmt.service.dao.DeviceDao] is defined: expected single matching bean but found 2: [deviceDao, jdbcDeviceDao]

from a class trying to autowire the bean like this

@Autowired
private DeviceDao hibernateDevicDao;

because there are two beans implementing the same interface.

The question:

Is it possible to configure the beans so that

1. I don’t have to make changes to existing classes, which already have the HibernateDeviceDao autowired

2. still being able to use the second (new) bean like this:

@Autowired
@Qualifier("jdbcDeviceDao")

I.e. i would need a way to configure the HibernateDeviceDao bean as the default bean to be autowired, simultaneously allowing the usage of a the JdbcDeviceDao when explicitly specifying so with the @Qualifier annotation.

What I’ve already tried:

I tried setting the property

autowire-candidate="false"

in the bean configuration for JdbcDeviceDao:

<bean id="jdbcDeviceDao" class="com.initech.service.dao.jdbc.JdbcDeviceDao" autowire-candidate="false">
    <property name="dataSource" ref="jdbcDataSource"/>
</bean>

because the Spring documentation says that

Indicates whether or not this bean should be considered when
looking for matching candidates to satisfy another bean’s
autowiring requirements. Note that this does not affect explicit
references by name, which will get resolved even if the specified
bean is not marked as an autowire candidate.*

which I interpreted to mean that I could still autowire JdbcDeviceDao using the @Qualifier annotation and have the HibernateDeviceDao as default bean. Apparently my interpretation was not correct, though, as this results in the following error message when starting the server:

Unsatisfied dependency of type [class com.sevenp.mobile.samplemgmt.service.dao.jdbc.JdbcDeviceDao]: expected at least 1 matching bean

coming from the class where I’ve tried autowiring the bean with a qualifier:

@Autowired
@Qualifier("jdbcDeviceDao")

Solution:

skaffman’s suggestion to try the @Resource annotation worked. So the configuration has autowire-candidate set to false for jdbcDeviceDao and when using the jdbcDeviceDao I refer to it using the @Resource annotation (instead of @Qualifier):

@Resource(name = "jdbcDeviceDao")
private JdbcDeviceListItemDao jdbcDeviceDao;
  • 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-03T15:44:20+00:00Added an answer on June 3, 2026 at 3:44 pm

    I’d suggest marking the Hibernate DAO class with @Primary, i.e. (assuming you used @Repository on HibernateDeviceDao):

    @Primary
    @Repository
    public class HibernateDeviceDao implements DeviceDao
    

    This way it will be selected as the default autowire candididate, with no need to autowire-candidate on the other bean.

    Also, rather than using @Autowired @Qualifier, I find it more elegant to use @Resource for picking specific beans, i.e.

    @Resource(name="jdbcDeviceDao")
    DeviceDao deviceDao;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a java web application wired using Spring on Tomcat. I need a
I'm new to Kohana but come from a Spring/Java background. In Spring I'm used
I have the following Java code: public static void main(String[] args) { new Thread(new
Say I have the following code: import java.lang.InterruptedException; import javax.swing.SwingWorker; public class Test {
I have the following Java Program which one starts in about 50% of all
Background: we have an application that generates reports from HTML (that may or may
Background: I have a module which declares a number of instance methods module UsefulThings
Background I have an application written in native C++ over the course of several
Background I have a Spring batch program that reads a file (example file I
The problem: you have a zipped java project distribution, which depends on several libraries

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.