Liferay + AspectJ在版本升级后无法正常工作

时间:2015-11-18 11:11:36

标签: java logging liferay aspectj

在Liferay 6.1下的项目中,我们有1个方面类 - TimedMethod,我们将其添加到我们想要记录执行时间的方法中。我们有一个jar org.aspect.runtime_1.7.3,它在Liferay 6.1上没问题。升级到6.2之后,我们必须解决许多问题。其中之一是不起作用的方面。我们在整个项目中只有一个。 这是aop.xml:

<aspectj>
 <weaver>
      <include within="com.*"/>
 </weaver>
 <aspects>
      <aspect name="com.dzi.portal.timedMethod.TimedMethodLogger"/>
 </aspects>
</aspectj>

方面的代码是

@Aspect
public class TimedMethodLogger {
    private Logger LOGGER = LoggerUtil.getLoggerForUser();  
    private static int level = 0;

    @Around(value = "execution(@TimedMethod * *(..))")
    public Object logMethod(ProceedingJoinPoint pjp) throws Throwable {
        String tabs = writeTab(level);

        LOGGER.info((level == 0 ? "First called method: " : tabs + "Level:" +     level + " Called method: ") + pjp.getSignature().toLongString());

        Date start = new Date();
        level++;
        Object methodResult = pjp.proceed();
        level--;
        Date end = new Date();

        Double executionTime = (double) (end.getTime() - start.getTime());
        if (executionTime != 0) {
            executionTime /= 1000;
        }

        String message = tabs + "End of method: " +     pjp.getSignature().toShortString() + " -> Time of execution: " + executionTime +     " seconds"
            + (level == 0 ? LoggerUtil.newLine + LoggerUtil.dashSplit : "");
    executionTime);

    LOGGER.info(message);

    return methodResult;
}

TimedMethod是:

@Retention(RetentionPolicy.RUNTIME)
@Target(value = { ElementType.METHOD })
public @interface TimedMethod {
}

我们将@TimedMethod放在我们想要登录的方法之前。服务器不会抛出异常。任何想法可能是什么原因?

0 个答案:

没有答案