• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1436
  • Last Modified:

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

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
fesit
Asked:
fesit
  • 2
1 Solution
 
dnunes_brCommented:
I think the problem is that * (asterisk) on the file name on this line:
appCtx = new ClassPathXmlApplicationContext("/WEB-INF/applicationContext*.xml");
0
 
fesitAuthor Commented:
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
 
fesitAuthor Commented:
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
 
bentleyforbesCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now