切面是这样定义的:@Aspect
public class LogAspect {

@Autowired
private SysLogService slService;
    
@Around("execution(* com.app.*.controller.*Controller.*(..)) && @annotation(annotation)")    
    public Object advice(ProceedingJoinPoint joinPoint, LogDesc annotation) throws Throwable {
    Object result = null;
    boolean ifEnd = false;
     try {
         result = joinPoint.proceed();
         ifEnd = true;
     }catch(Exception ex) {
         throw new Exception("操作异常");    
     } finally {
    this.saveLog(joinPoint, annotation, ifEnd); 
     } 
     return result;
    
    }    
自定义注解类:@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface LogDesc {
String operType() default "0";
String desc() default "";
}
-servlet.xml文件中注册切面<aop:aspectj-autoproxy /> 和<aop:aspectj-autoproxy proxy-target-class="true"/>都试过了。登陆controller标注如下:    @RequestMapping(method = RequestMethod.POST)
    @LogDesc(desc = "用户登录", operType = LogType.LOGIN)
    public String doLogin(HttpServletRequest request,HttpServletResponse response, ModelMap model)
现在的问题就是登陆的时候没有拦截。
我在想原因是不是这样:
就好比说东西在那了,但是怎么找东西的问题
在切面类里在哪里定义找哪个标记的问题。
是不是还需要在配置文件里配置些什么东西?
请教各位大神!

解决方案 »

  1.   

    spring mvc我没用过,但在ssh下我帮过AOP日志。
    @annotation(annotation)这里面的annotation改为com.xx.xx.logDesc
      

  2.   

    "execution(* com.app.*.controller.*Controller.*(..)) 你再把这里去掉试试看!
      

  3.   

    你定位改一下呢?
    比如:
    @After("execution(* com.orientpay.oecs.*.service..*.update(..))")
    定位一道service层
    不要用控制层
      

  4.   

    类注解:
    @Service
    @Aspect
    @Order(value=3)
    public class OperateInterceptor{方法注解:
    @After("execution(* com.orientpay.oecs.*.service..*.update(..))")
      

  5.   

    首先不知道楼主LogAspect类,有没有@component注解,如果没有肯定是拦截不到的,其次
    execution(* com.app.*.controller.*Controller.*(..)) && @annotation(annotation),不知道楼主的doLogin匹不匹配这个表达式,建议先把&& @annotation(annotation)去掉试试
      

  6.   

    Controller拼错没  包和类都检查一下
      

  7.   

    把public String doLogin()方法所在的包及类贴出来,看看匹不匹配这个表达式 execution(* com.app.*.controller.*Controller.*(..)) 
      

  8.   


    package com.app.system.controller
      

  9.   

    servlet.xml文件中注册切面是spring的配置文件吗,如果是在里面加上<context:annotation-config />另外再看 doLogin的类名匹不匹配*Controller