Spring Boot,@ Configurable LoadTimeWeaving,Tomcat 8 – IllegalStateException

在我的
Spring Boot 1.3.3中,Tomcat 8(用于开发的嵌入式,用于生产的独立)应用程序我将从Spring Proxy Transactional Mode转移到AspectJ事务.

我添加了以下应用程序配置:

@EnableAsync
@ComponentScan("com.example")
@EntityScan("com.example")
@EnableJpaRepositories("com.example")
@EnableTransactionManagement(mode=AdviceMode.ASPECTJ)
@EnableLoadTimeWeaving(aspectjWeaving=AspectJWeaving.ENABLED)
@Configuration
public class ApplicationConfiguration implements LoadTimeWeavingConfigurer {

    @Override
    public LoadTimeWeaver getLoadTimeWeaver() {
        return new ReflectiveLoadTimeWeaver();
    }

}

但是在嵌入式Tomcat 8上的应用程序启动期间(不在Standalone Tomcat上测试它)我遇到以下异常:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.instrument.classloading.LoadTimeWeaver]: Factory method 'loadTimeWeaver' threw exception; nested exception is java.lang.IllegalStateException: ClassLoader [sun.misc.Launcher$AppClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method.
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
    ... 18 common frames omitted
Caused by: java.lang.IllegalStateException: ClassLoader [sun.misc.Launcher$AppClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method.

我的配置有什么问题/不存在以及如何解决这个问题?

最佳答案 我自己过去曾经看过这个,我相信你需要用java代理运行你的应用程序来启用嵌入式tomcat的加载时编织.让aspectjweaver和spring-instrument罐子都准备好并尝试启动你的应用程序:

java -javaagent:path/to/aspectjweaver-1.8.2.jar -javaagent:path/to/spring-instrument.jar -jar path/to/your/app.jar
点赞