AspectJ @around a static initializer
I accepted that answer because it did apply the aspect to the code, but i hadn't actually run it yet to see there were still problems...
I have this aspect
Code: Select all
package com.acme.aspects.exceptions;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Aspect
public class StaticInitializerExceptions {
private static final Logger LOGGER = LoggerFactory.getLogger(StaticInitializerExceptions.class);
@Around("staticinitialization(!is(InterfaceType)) && !within(MyAspect) && !within(com.acme.aspects.exceptions.StaticInitializerExceptions)")
public Object logStaticInitializerException(ProceedingJoinPoint joinPoint) throws Throwable {
try {
return joinPoint.proceed();
} catch (Throwable t) {
LOGGER.error("STATIC INITIALIZER EXCEPTION CAUGHT", t);
throw t;
}
}
}
Code: Select all
public class AcmeContextListener implements ServletContextListener {
private static final Logger LOGGER = LoggerFactory.getLogger(AcmeContextListener.class);
....
}
< /code>
Dann wird es klinit so gewehrt, dass der
logger = loggerfactory.getLogger (AcmecontextListener.Class); < /p>
wird nicht aus der Klinit-Erzeugung aufgerufen. PrettyPrint-Override "> - STATIC INITIALIZER EXCEPTION CAUGHT
at com.acme.listener.AcmeContextListener.clinit$_aroundBody0(AcmeContextListener.java:20) ~[_servlets.jar:25.6.0.0]
at com.acme.listener.AcmeContextListener.clinit$_aroundBody1$advice(AcmeContextListener.java:17) ~[_servlets.jar:25.6.0.0]
java.lang.IllegalAccessError: Update to static final field com.acme.listener.AcmeContextListener.LOGGER attempted from a different method (clinit$_aroundBody0) than the initializer method
at com.acme.listener.AcmeContextListener.(AcmeContextListener.java:1) ~[_servlets.jar:25.6.0.0]