切面是这样定义的:@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)
现在的问题就是登陆的时候没有拦截。
我在想原因是不是这样:
就好比说东西在那了,但是怎么找东西的问题
在切面类里在哪里定义找哪个标记的问题。
是不是还需要在配置文件里配置些什么东西?
请教各位大神!
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)
现在的问题就是登陆的时候没有拦截。
我在想原因是不是这样:
就好比说东西在那了,但是怎么找东西的问题
在切面类里在哪里定义找哪个标记的问题。
是不是还需要在配置文件里配置些什么东西?
请教各位大神!
@annotation(annotation)这里面的annotation改为com.xx.xx.logDesc
比如:
@After("execution(* com.orientpay.oecs.*.service..*.update(..))")
定位一道service层
不要用控制层
@Service
@Aspect
@Order(value=3)
public class OperateInterceptor{方法注解:
@After("execution(* com.orientpay.oecs.*.service..*.update(..))")
execution(* com.app.*.controller.*Controller.*(..)) && @annotation(annotation),不知道楼主的doLogin匹不匹配这个表达式,建议先把&& @annotation(annotation)去掉试试
package com.app.system.controller