Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2008-11-19
4
Medium Priority
?
1,371 Views
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"/>
</bean>

Within the file "..UserDaoTest.java", 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 {
        super.setUp();
        appCtx = new ClassPathXmlApplicationContext("/WEB-INF/applicationContext*.xml");
        dao = (UserDao) appCtx.getBean("userDao");
    }

    public void testSaveUser() thorws Exception {
        user = new User();
        user.setUsername("Jane");
        user.setPassword("123");
        ...

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
org.springframework.beans.factory.NoSuchBeanDefinition
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition( DefaultListableBeanFactory.java.387)

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.
0
Comment
Question by:fesit
  • 2
4 Comments
 
LVL 6

Expert Comment

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

Author Comment

by:fesit
ID: 23006762
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.
0
 

Accepted Solution

by:
fesit earned 0 total points
ID: 24130220
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.
0
 

Expert Comment

by:bentleyforbes
ID: 26506790
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.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There is a huge demand for CodeIgniter among the PHP web developers due to its dynamic features and benefits these days. It is one of most popular and agile open source PHP framework for creating robust web applications in PHP web development field.…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month21 days, 2 hours left to enroll

810 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