Search code examples
javaspringaspectj

ClassLoader does NOT provide an 'addTransformer(ClassFileTransformer)' method


I'm using Spring and AspectJ to do some nice weaving and I just ran into this issue after inserting <context:load-time-weaver/> into my application context:

Caused by: java.lang.IllegalStateException: ClassLoader [sun.misc.Launcher$AppClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar
    at org.springframework.context.weaving.DefaultContextLoadTimeWeaver.setBeanClassLoader(DefaultContextLoadTimeWeaver.java:83)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1419)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1391)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
    ... 21 common frames omitted

Do I need a custom JVM to run AspectJ?!? I can't ever remember having to do this before.


Solution

  • I can't find any documentation to support it, but I'm fairly certain that the standard JVM doesn't support Spring's style of load-time weaving. Spring's guide to enabling LTW in different environments implies that this is the case in its "Generic Java applications" section.