springboot-aop无法获取joinPoint参数的类对象

时间:2018-08-11 16:24:25

标签: java spring-boot aop spring-aop

我试图在Spring AOP上获取一些方法参数,然后尝试使用getClass()获取参数的Class对象,但是我无法获取诸如java.sql.Time这样的Class对象,它将抛出java.lang.NullPointerException。有代码片段:

com.example.vzard.web.TUserController.java

@RequestMapping(value = "/user",method = RequestMethod.POST)
@TimeStamp(type = TUser.class)
 public boolean addUser(TUser user, Object o, Time time){
        return itUserService.insertAllColumn(user);
    }

com.example.vzard.annotation.TimeStamp.java

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface TimeStamp {
    Class type() default Object.class;

    TimeStampRank rank() default TimeStampRank.FULL;
}

com.example.vzard.aspect.TimeStampAspect.java

@Pointcut("@annotation(com.example.vzard.annotation.TimeStamp)")
public void pointCut(){

}

@Before("pointCut() && @annotation(timeStamp)")
public void before(JoinPoint joinPoint,TimeStamp timeStamp){
    Long currentTime = System.currentTimeMillis();
    Class type = timeStamp.type();

    Object[] argList = joinPoint.getArgs();
    System.out.println(argList.length);
    for (Object arg : argList) {
        //there will throw Exception
        log.info(arg.getClass().toString());

    }

}

当我将某个类中的java.sql.Time替换为空构造函数时,我发现它可能与参数类是否具有空构造函数有关 可以,但是我不确定这是否是真正的原因。

0 个答案:

没有答案