spring配置aop后,struts2的请求全部失效了,请问这是什么原因?

spring配置

    <!-- ##########################aop start########################## -->
    <!-- 启用AOP -->  
    <aop:aspectj-autoproxy />
    <!-- aop日志记录方法 -->
    <bean id="sysLogAspect" class="com.otw.common.aspect.SysLogAspect"/>
    <!-- 配置AOP -->
    <aop:config>
        <!-- 配置切点表达式  -->
        <aop:pointcut id="sysLogPointcut" expression="execution(* com.otw.web.action.*.*(..))" />
        <!-- 配置切面及配置 -->
        <aop:aspect ref="sysLogAspect">     
            <!-- 环绕增强 -->
            <aop:around method="around" pointcut-ref="sysLogPointcut" />
        </aop:aspect>
    </aop:config>
    <!-- ##########################aop end########################## -->
/*
 * 描述:
 * 修改人:17109
 * 修改时间:2018年3月13日
 */

package com.otw.common.aspect;


import java.lang.reflect.Method;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.SecurityUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;

import com.google.gson.Gson;
import com.otw.common.annotation.SysLogAnnotation;
import com.otw.utils.HttpContextUtils;
import com.otw.utils.IPUtils;
import com.otw.web.pojo.SysLog;
import com.otw.web.pojo.SysLogin;
import com.otw.web.service.SysLogService;


@Aspect
public class SysLogAspect
{
    @Autowired
    private SysLogService sysLogService;

    @Pointcut("@annotation(com.otw.common.annotation.SysLogAnnotation)")
    public void logPointCut()
    {

    }

    @Around("logPointCut()")
    public Object around(ProceedingJoinPoint point)
        throws Throwable
    {
        long beginTime = System.currentTimeMillis();
        // 执行方法
        Object result = point.proceed();
        // 执行时长(毫秒)
        long time = System.currentTimeMillis() - beginTime;

        // 保存日志
        saveSysLog(point, time);

        return result;
    }

    private void saveSysLog(ProceedingJoinPoint joinPoint, long time)
    {
        MethodSignature signature = (MethodSignature)joinPoint.getSignature();
        Method method = signature.getMethod();

        SysLog sysLog = new SysLog();
        SysLogAnnotation sysLogAnnotation = method.getAnnotation(SysLogAnnotation.class);
        if (sysLogAnnotation != null)
        {
            // 注解上的描述
            sysLog.setOperation(sysLogAnnotation.value());
        }

        // 请求的方法名
        String className = joinPoint.getTarget().getClass().getName();
        String methodName = signature.getName();
        sysLog.setMethod(className + "." + methodName + "()");

        // 请求的参数
        Object[] args = joinPoint.getArgs();
        try
        {
            String params = new Gson().toJson(args[0]);
            sysLog.setParams(params);
        }
        catch (Exception e)
        {

        }

        // 获取request
        HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
        // 设置IP地址
        sysLog.setIp(IPUtils.getIpAddr(request));

        // 用户名
        String username = ((SysLogin)SecurityUtils.getSubject().getPrincipal()).getName();
        sysLog.setUsername(username);

        sysLog.setTime(time);
        sysLog.setCreateDate(new Date());
        // 保存系统日志
        sysLogService.insert(sysLog);
    }
}
/**
 * 系统日志注解
 *
 * @author linyuting
 * @since 2018-3-13
 */
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface SysLogAnnotation {

    String value() default "";
}
阅读 2.9k
1 个回答
新手上路,请多包涵

你把com.otw.common.annotation.SysLogAnnotation这个文件贴出来看一下

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题