No bean named 'userDao' is defined within applicationContext.xml

Posted on 2008-11-19
Last Modified: 2012-05-05
Within the file "../WEB-INF/applicationContext.xml", I have the 'userDao' bean defined as such:

<bean id="userDao" class="dao.hibernate.UserDaoHibernate">
    <property name="sessionFactory" ref="sessionFactory"/>

Within the file "", I have the following declared:
public class UserDaoTest extends TestCase{

    private User user = null;
    private UserDao dao = null;

    protected ApplicationContext appCtx = null;

   protected void setUp() throws Exception {
        appCtx = new ClassPathXmlApplicationContext("/WEB-INF/applicationContext*.xml");
        dao = (UserDao) appCtx.getBean("userDao");

    public void testSaveUser() thorws Exception {
        user = new User();

When I run the test file, I get the following errors:
dao.UserDaoTest  FAILED
testSaveUser  caused an ERROR (0.015s)
No bean neamed 'userDao' is defined

Is there something that I'm defining incorrectly or missing that's causing this to fail?  Thanks ahead of time for any input and effort.
Question by:fesit
    LVL 6

    Expert Comment

    I think the problem is that * (asterisk) on the file name on this line:
    appCtx = new ClassPathXmlApplicationContext("/WEB-INF/applicationContext*.xml");

    Author Comment

    I've tried with and without the * (asterisk) within the file name.  Without the asterisk, the file can not be found.  With the asterisk, file is found but bean is not found within the file.

    Accepted Solution

    Backed up the project under a different name and built new project with old name.  Rewrote all of the source code and for some reason, it compiled without a problem.  When both of the project folders were compared(utilizing beyondcompaire) the files were the same except for time stamps.  Since this process was done, I have not re-encounter this problem again.  Will keep you all updated if I find out more info regarding this.

    Expert Comment

    for those of you who may have found this via a search - this may occur if your classpath contains an older version of the applicationContext.xml file (either resident on the server or in some other location on your classpath) which may not be updated when you update the application during the edit and deploy process. Perform a search on your system, locate any applicationContext.xml file - open it, if the file is associated with your application, verify that it references beans which you've added in your most recent iteration of development. If not, and you prefer not to delete these files, update their contents by copying and pasting the most updated applicationContext file into the ones which are found. I hope this makes sense.

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
    This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now