Why can't I get @EnableLoadTimeWeaving in spring boot web with embedded tomcat

Viewed 2051

I am writing a spring boot web application packaged as a executable jar file and I need load time AspectJ weaving. Using -javaagent is not an option for me as it will require our DevOps to change the deployment toolchain, which I don't want to deal with right now. Here is my Main class.

@SpringBootApplication
@EnableLoadTimeWeaving(aspectjWeaving=AspectJWeaving.ENABLED)
public class Application extends SpringBootServletInitializer {
  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }

  @Bean
  public LoadTimeWeaver loadTimeWeaver() {
    return new InstrumentationLoadTimeWeaver();
  }
}

This did not work. I thought maybe injecting InstrumentationLoadTimeWeaver is not playing well with embedded Tomcat. I tried replacing it with TomcatLoadTimeWeaver. But the result was that spring context failed to load with the following error message.

Caused by: java.lang.IllegalStateException: Could not initialize TomcatLoadTimeWeaver because Tomcat API classes are not available

This bug on spring-boot github issues concludes that currently AspectJ load time weaving cannot be used with embedded tomcat. My question is why is it not possible? I want to understand what is the load time weaving mechanism which makes it impossible to work in an executable Spring boot web jar.

0 Answers
Related