0
votes

I'm using Spring-AOP to advise a spring managed bean that extends an abstract class which implements 3 interfaces. There are other spring-managed beans around in the inheritance hierarchy.

I'm trying to take the least-invasive approach, using spring-LTW:

<context:component-scan base-package="com.foo.aop"/>
<!-- ... -->
<aop:aspectj-autoproxy proxy-target-class="true"/>
<context:load-time-weaver/>

Using the kitchen-sink approach to try to get logging to happen:

@Aspect
@Component
public class ForStackOverflow {

    private final Log commons = LogFactory.getLog(ForStackOverflow.class);
    private final org.apache.log4j.Logger log4j = org.apache.log4j.Logger.getLogger(ForStackOverflow.class);
    private final Logger jul = Logger.getLogger(ForStackOverflow.class.getSimpleName());
    private final org.slf4j.Logger slf4j = org.slf4j.LoggerFactory.getLogger(ForStackOverflow.class);

    @Pointcut(value="within(com.foo.aop.AbstractClass+) " +
                    "&& execution(* advisedMethod(com.foo.SomeType)) " +
                    "&& args(someType)")
    private void adviseMe(SomeType someType){}

    @After(value="adviseMe(com.foo.SomeType) && args(someType)", argNames = "someType")
    public void itWorked(SomeType someType) {
        String msg = "DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG";
        logIt(msg);               
        IsNotNull(someType, "someType");
        String message = "SomeType [ " + someType + "] loaded.";
        status(message);
        logIt(msg);
    }

    void status(String message) {        
        logIt(message);
    }

    private void logIt(String msg){
        System.out.println("STDOUT: " + msg);
        System.err.println("STDERR: " + msg);
        commons.warn("COMMONS: " + msg);
        log4j.warn("LOG4J: " + msg );
        jul.warning("JUL: " + msg);
        slf4j.warn("SLF4J: " + msg );
    }
}

I have evidence that my method is being advised, because I can throw from there and see the stack trace pop out in the appropriate place.

But logging is elusive.

(I'm bridging log4j and commons-logging to slf4j. The application requires java util logging as its underlying implementation.)

1
And where is a question mark in your question? - kan

1 Answers

0
votes

most likely you have forgotten to add jvm parameter -javagent or you are not including META-INF\aop.xml file on your application classpath

please refer below answer for details

Spring load time weaving not detecting class annotated with @configurable