3

In my Spring Boot 1.3.3, Tomcat 8(Embedded for development, Standalone for production) application I'm going to move away from Spring Proxy Transactional Mode to AspectJ transactions.

I have added a following application configuration:

@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();
    }

}

but during the application startup on Embedded Tomcat 8(do not tested it on Standalone Tomcat) I got a following exception:

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.

What is wrong/absent in my configuration and how to solve this issue ?

alexanoid
  • 24,051
  • 54
  • 210
  • 410

1 Answers1

2

I've seen this myself in the past and I believe you need to run your application with a java agent to enable load-time weaving with the embedded tomcat. Have both the aspectjweaver and spring-instrument jars ready and try starting your app with:

java -javaagent:path/to/aspectjweaver-1.8.2.jar -javaagent:path/to/spring-instrument.jar -jar path/to/your/app.jar
zybreak
  • 86
  • 7