Spring Boot,@Configurable LoadTimeWeaving,Tomcat 8 - IllegalStateException

标签 spring tomcat spring-boot spring-transactions spring-aspects

在我的 Spring Boot 1.3.3 Tomcat 8(嵌入式开发,独立生产)应用程序中,我将从 Spring 代理事务模式转移到 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();
    }

}

但是在 Embedded 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 jar 并尝试使用以下命令启动您的应用:

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

关于Spring Boot,@Configurable LoadTimeWeaving,Tomcat 8 - IllegalStateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37223940/

相关文章:

jsp - 在 JSP 页面中动态导入文件

java - 关闭 tomcat 服务器时无法加载 org.apache.hadoop.util.ShutdownHookManager

docker - spring boot mvc docker Whitelabel错误

Spring 批处理 : Retry job if does not complete in particular time

java - Spring事务边界和DB连接保持

java - Jetty 的轻量级替代品

java - 在 Spring Boot 中实现简单的异步方法调用时遇到问题

maven - 在 pom.xml 中为 Kotlin 中的 Spring Boot 项目指定 Main 类

Spring的TransactionInterceptor覆盖了我的异常

java - spring mvc项目中的org.springframework.beans.factory.BeanCreationException