500 错误——无法加载BeanClassException

时间:2021-07-18 23:02:17

标签: spring http-status-code-500

我的 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>

1 个答案:

答案 0 :(得分:0)

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

相关问题