500 错误——CannotLoadBeanClassException

500 error -- CannotLoadBeanClassException

我的 Spring Web 应用程序出现 500 错误。提到的文件已正确命名并位于正确的包中。这是错误消息。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping': Invocation of init method failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.dao.CommentDAO] for bean with name 'commentDAO' defined in ServletContext resource [/WEB-INF/ghs1986-servlet.xml]; nested exception is java.lang.ClassNotFoundException: com.dao.CommentDAO
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.dao.CommentDAO] for bean with name 'commentDAO' defined in ServletContext resource [/WEB-INF/ghs1986-servlet.xml]; nested exception is java.lang.ClassNotFoundException: com.dao.CommentDAO
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.controller.PagesController] for bean with name 'pagesController' defined in ServletContext resource [/WEB-INF/ghs1986-servlet.xml]; nested exception is java.lang.ClassNotFoundException: com.controller.PagesController
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.controller.CommentController] for bean with name 'commentController' defined in ServletContext resource [/WEB-INF/ghs1986-servlet.xml]; nested exception is java.lang.ClassNotFoundException: com.controller.CommentController

这里是 ghs1986-servlet.xml.

的相关部分
<bean id="commentDAO" class="com.dao.CommentDAO">
        <property name="dataSource" ref="dataSource" />
    </bean>

    <bean id="pagesController" class="com.controller.PagesController" />

    <bean id="commentController" class="com.controller.CommentController">
        <property name="commentDAO" ref="commentDAO" />
    </bean>

问题已解决。我需要 CommentDAO 上的 @Component 注释。