Exception: Must start with Java agent to use InstrumentationLoadTimeWeaver. See Spring documentation

笑着哭i 提交于 2019-12-05 15:09:15

As the exception says, check the documentation and try running your test with "-javaagent", for example:

-javaagent:C:\Users\whatever\.m2\repository\org\springframework\spring-instrument\3.2.5.RELEASE\spring-instrument-3.2.5.RELEASE.jar
user3805618

This worked for me using:

spring-boot 1.5.3.RELEASE
spring-data 1.5.3.RELEASE

org.eclipse.persistence.jpa <version>2.6.4</version>
    </dependency>

In the configuration class add:

@Configuration
@EnableLoadTimeWeaving(aspectjWeaving = EnableLoadTimeWeaving.AspectJWeaving.ENABLED)

@Bean
public InstrumentationLoadTimeWeaver loadTimeWeaver()  throws Throwable {
    InstrumentationLoadTimeWeaver loadTimeWeaver = new InstrumentationLoadTimeWeaver();
    return loadTimeWeaver;
}

Set properties file to:

eclipselink.weaving=false

And set Vm argument to local server via:

-javaagent:<path_to_maven_REPO>\org\springframework\spring-instrument\4.3.9.RELEASE\spring-instrument-4.3.9.RELEASE.jar

I had similar problem. My solution was adding a line to context.xml on tomcat conf directory.

<Context>
...
    <Loader delegate="true"/>
...
</Context>

If you are running maven like build, include an extra configuration to your surefire plugin, as show in this snippet (don't forget to include ${spring-version} property in your pom.xml):

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.21.0</version>
    <configuration>
      <forkMode>once</forkMode>
      <argLine>
        -javaagent:"${settings.localRepository}/org/springframework/spring-instrument/${spring.version}/spring-instrument-${spring.version}.jar"
      </argLine>
    </configuration>
  </plugin>

Detail in this answer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!