简体   繁体   English

必须启动InstrumentationLoadTimeWeaver / openjdk 11

[英]Must start InstrumentationLoadTimeWeaver / openjdk 11

We have a production Java 1.6 / Tomcat 7 / Spring 4 application. 我们有一个生产Java 1.6 / Tomcat 7 / Spring 4的应用程序。

We are moving it to Openjdk 11. This means Spring 5 and I figure it might as well include Tomcat 9 since we're updating everything else. 我们将其移至Openjdk11。这意味着Spring 5和我认为它可能还包括Tomcat 9,因为我们正在更新其他所有内容。

The problem is the self explanatory sounding: 问题是自我解释的声音:

ERROR org.springframework.web.context.ContextLoader - Context initialization failed org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'rootContextConfig': Unsatisfied dependency expressed through field 'entityManagerFactory'; 错误org.springframework.web.context.ContextLoader-上下文初始化失败org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为'rootContextConfig'的bean时出错:未通过字段'entityManagerFactory'表示的依赖关系; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in com.xxxxx.config.RootContextConfig: Invocation of init method failed; 嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建在com.xxxxx.config.RootContextConfig中定义的名称为'entityManagerFactory'的bean时出错:调用init方法失败; nested exception is java.lang.IllegalStateException: Must start with Java agent to use InstrumentationLoadTimeWeaver. 嵌套异常为java.lang.IllegalStateException: 必须以Java代理开头才能使用InstrumentationLoadTimeWeaver。 See Spring documentation. 参见Spring文档。

All well and good. 一切都很好。 Only problem is that we already have the Spring Insturment Java agent 唯一的问题是我们已经有了Spring Insturment Java代理

-javaagent:${CATALINA_HOME}/lib/spring-instrument-5.1.5.RELEASE.jar

Like I said above this is all working code we are just updating versions. 就像我上面说的那样,这是所有工作代码,我们只是在更新版本。

I am confident the LTW is being loaded because we can see the error being produced by InstrumentationLoadTimeWeaver class. 我有信心正在加载LTW,因为我们可以看到InstrumentationLoadTimeWeaver类产生的错误。

@Override
public void addTransformer(ClassFileTransformer transformer) {
    Assert.notNull(transformer, "Transformer must not be null");
    FilteringClassFileTransformer actualTransformer =
            new FilteringClassFileTransformer(transformer, this.classLoader);
    synchronized (this.transformers) {
        Assert.state(this.instrumentation != null,
                "Must start with Java agent to use InstrumentationLoadTimeWeaver. See Spring documentation.");
        this.instrumentation.addTransformer(actualTransformer);
        this.transformers.add(actualTransformer);
    }
}

I just can't figure out how it can get instantiated with a null instrumentation. 我只是想不通如何使用null工具实例化它。 Obviously I'm missing something. 显然我缺少了一些东西。 Probably something small and stupid. 可能是一些小而愚蠢的东西。 But right now I'm out of ideas. 但是现在我没主意了。

It seems that problem is with classloading 看来问题在于类加载

  1. Add '-verbose:class' option to see if InstrumentationLoadTimeWeaver was loaded 添加'-verbose:class'选项以查看是否加载了InstrumentationLoadTimeWeaver

  2. try to add this option to you tomcat contexct configuration <Context> ... <Loader delegate="true"/> ... </Context> 尝试将此选项添加到您的tomcat contexct配置<Context> ... <Loader delegate="true"/> ... </Context>

There were some changes in Tomcat 7.0.27 which can trigger this problem Tomcat 7.0.27中有一些更改可以触发此问题

Make the implementation of Catalina.getParentClassLoader consistent with similar methods across the code base and have it return the system class loader if no parent class loader is set. 使Catalina.getParentClassLoader的实现与整个代码库中的类似方法保持一致,如果未设置父类加载器,则使它返回系统类加载器。 (markt) (Markt的)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM