@Aspect
@Component
public class WeiXinRegister {
@Pointcut("execution(public * com.workit.wx.*.controller..*.*(..))")
public void pointcut() {
}
/**
* 该标签声明次方法是一个前置通知:在目标方法开始之前执行
*
* @param joinPoint
*/
@Before("pointcut()")
public void beforMethod(JoinPoint joinPoint) throws Throwable {
Object[] args = joinPoint.getArgs();
HttpServletRequest request = null;
HttpServletResponse response = null;
for (int i = 0; i < args.length; i++) {
if (args[i] instanceof HttpServletRequest) {
request = (HttpServletRequest) args[i];
}
if (args[i] instanceof HttpServletResponse) {
response = (HttpServletResponse) args[i];
}
}
if (request == null || response == null) {
return;
}
}
<!-- aop开启注解扫描 -->
<context:component-scan base-package="com.workit.wx.aspect"></context:component-scan>
<aop:aspectj-autoproxy proxy-target-class="true" />
这个放在spring mvc 配置文件中