Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/lang/NoAspectBoundException

Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/lang/NoAspectBoundException

我在使用 AspectJ 时遇到错误:

控制器:

@RequestMapping("/logout")
public ModelAndView Logout(
    Locale locale,
    Model model,
    HttpServletRequest request
) throws ParseException {
    NguoiDung student = new NguoiDung();
    student = (NguoiDung) request.getSession().getAttribute("customer");
    String email = student.getEmail();
    dangxuat(email);
    request.getSession().removeAttribute("chuyentrang");
    request.getSession().removeAttribute("nguoidung");
    request.getSession().removeAttribute("customer");
    return new ModelAndView("login");
}

Class LoggingAspectJ

public aspect LoggingAspectJ {
    pointcut callLogout(String email) :
        call(* StudentController.dangxuat(String)) &&
        args(email) && 
        within(StudentController);

    after(String email) : callLogout(email) {
        System.out.println("Logout");
    }
}

当我选择注销时,出现以下错误:

类型

Exception report

留言

Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/lang/NoAspectBoundException

描述

The server encountered an internal error that prevented it from fulfilling this request.

异常

org.springframework.web.util.NestedServletException: Handler
processing failed; nested exception is java.lang.NoClassDefFoundError:
org/aspectj/lang/NoAspectBoundException
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:839)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

根本原因

java.lang.NoClassDefFoundError:
org/aspectj/lang/NoAspectBoundException
    com.joseph.controller.StudentController.Logout(StudentController.java:124)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

根本原因

java.lang.ClassNotFoundException:
org.aspectj.lang.NoAspectBoundException
    org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1305)
    org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1157)
    com.joseph.controller.StudentController.Logout(StudentController.java:124)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

AspectJ 运行时库aspectjrt.jar(名称可能还包含版本号,具体取决于您从何处获取库)必须在类路径中。显然不是。