how to setup load-time weaving with Spring and Tomcat WITHOUT using the -javaagent on the command line

后端 未结 3 1328
走了就别回头了
走了就别回头了 2021-01-12 14:40

I am using Spring 3.2.9, Tomcat 6.0.44

I am trying to configure my application\'s Spring instrumentation provider (e.g. spring-instrumentation.jar) for load-time wea

3条回答
  •  梦毁少年i
    2021-01-12 15:20

    I used invesdwin-instrument to perform that. It allows you to use Load time weaving instrumentation dynamically so that you don't have to use any javaagent.

    It took me a bit of effort to make it work with Tomcat 8.5 though. But it finally work using this configuration with Spring Boot :

    @SpringBootApplication
    @EnableLoadTimeWeaving // instead of @ImportResource(locations = "classpath:/META-INF/ctx.spring.weaving.xml")
    public class MySpringBootApplication {
        public static void main(final String[] args) {
            DynamicInstrumentationLoader.waitForInitialized(); //dynamically attach java agent to jvm if not already present
            DynamicInstrumentationLoader.initLoadTimeWeavingContext(); //weave all classes before they are loaded as beans
            SpringApplication.run(MySpringBootApplication.class, args); //start application, load some classes
        }
    }
    

    It should also work with previous version of Tomcat.

    Regards

提交回复
热议问题