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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:30:23+00:00 2026-05-26T23:30:23+00:00

I have one irritating problem right now. My tests fail due to an autowire.

  • 0

I have one irritating problem right now.
My tests fail due to an autowire.

Could not autowire field: private k.dao.CompanyDao k.dao.CompanyDaoTest.companyDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [k.dao.CompanyDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.

I think @ContextConfiguration can be the problem?

The test

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:**/servlet-context.xml", "classpath:**/root-context.xml", "classpath:**/ccc-jpa.xml" })
public final class CompanyDaoTest {

    @Autowired
    private CompanyDao companyDao;

    @Test
    public void testTest() {

    }
}

CompanyDao

public interface CompanyDao extends GenericDao<Company> {

}

CompanyDaoJpa

@Repository("companyDao")
public class CompanyDaoJpa extends GenericDaoJpa<Company> implements CompanyDao {

    public CompanyDaoJpa() {
        super(Company.class);
    }
}

GenericDao

public interface GenericDao<T extends DomainObject> {

    public T get(Long id);

    public List<T> getAll();

    public T save(T object);

    public T delete(T object);

}

servlet-context.xml

    <annotation-driven />

    <context:component-scan base-package="k"/>
  • 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-05-26T23:30:23+00:00Added an answer on May 26, 2026 at 11:30 pm

    I guess your test doesn’t load servlet-context.xml at all.

    You reference servlet-context.xml as a classpath resource, but servlet-context.xml is usually located under WEB-INF, which is not a part of application classpath. Note that Spring doesn’t complain about missing config files when they are referenced with wildcards ( classpath:**/servlet-context.xml), so that your test starts silently even if config files cannot be found.

    There are no good ways to access Spring xml files located in WEB-INF from unit tests. If you want to run tests against them, you need to move them to the classpath (i.e. to something like src or resources, depending on your project layout). Since DispatcherServlet and ContextLoaderListener expect to find these files under WEB-INF, you also need to reconfigure them using their respective contextConfigLocation parameters. For example, in the case of DispatcherServlet:

    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:**/servlet-config.xml</param-value>
    </init-param>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very irritating problem. I'm working with a list of documents, but
I found it irritating that if you run one command 5 times you have
I have tried and tried and tried now. I have a mysql field (TEXT)
I have one problem. I have EasyPHP server on my local computer. I am
have one problem, I need the dates in Swedish format, for instance, october is
I have one excel file (*.xlsm) with VBA code on first sheet: Private Sub
This is a really irritating problem to have that springs from poor process, I
I have one very tricky issue that I am not able to sort out
have one time consuming step that flattens a bunch of files. basically i'd like
I have one table having ID and other attributes. How can I get list

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.