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

拥有回忆 提交于 2019-12-12 15:08:12

问题


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.


回答1:


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.




回答2:


You might be using some other LoadTimeWeaver class like in my case it was org.springframework.instrument.classloading.websphere.WebSphereLoadTimeWeaver from spring-context-3.1.1.RELEASE.jar. My problem was spring-instrument-3.1.1.RELEASE.jar was in higher position class hierarchy than the spring-context jar. Which was being used as default agent.

Solution that worked for me: I just brought the instrument jar after spring context in the classpath hierarchy error just vanished.



来源:https://stackoverflow.com/questions/6989581/classloader-does-not-provide-an-addtransformerclassfiletransformer-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!