no bean named “userDao” is defined

前端 未结 1 1528
无人共我
无人共我 2021-01-25 16:11

I got this exception. This is my code:

ApplicationContext context = new ClassPathXmlApplicationContext(\"classpath*:/servlet-context.xml\");
UserDao userDao = (U         


        
相关标签:
1条回答
  • 2021-01-25 16:28

    classpath*:/servlet-context.xml will load every servlet-context.xml resource from the root of your application's classpath.

    /myproject/WebContent/WEB-INF/spring/appServlet/servlet-context.xml, however, isn't on the classpath root at all, and so Spring will ignore your file and build an empty context.

    Try moving servlet-context.xml to be directly under WEB-INF/classes (i.e. to WEB-INF/classes/servlet-context.xml).

    Alternatively, move it to WEB-INF/classes/spring/appServlet/servlet-context.xml, and change your code to classpath*:/spring/appServlet/servlet-context.xml

    0 讨论(0)
提交回复
热议问题