【问题标题】:Fix classloading issue with ByteBuddy and Vaadin in OSGi setup修复 OSGi 设置中 ByteBuddy 和 Vaadin 的类加载问题
【发布时间】:2020-02-09 20:20:33
【问题描述】:

我在 OSGi 设置中遇到 Vaadin 流问题,这似乎与使用 Polymer 模板时某些类在内部加载的方式有关。 这是我的一些细节问题https://github.com/vaadin/flow/issues/7377

TemplateModelProxyHandler:229ff中,下面的代码用于加载代理类

Class<?> proxyType = proxyBuilder

// Handle bean methods (and abstract methods for error handling)
.method(method -> isAccessor(method) || method.isAbstract())
.intercept(MethodDelegation.to(proxyHandler))

// Handle internal $stateNode methods
.defineField("$stateNode", StateNode.class)
.method(method -> "$stateNode".equals(method.getName()))
.intercept(FieldAccessor.ofField("$stateNode"))

// Handle internal $modelType methods
.defineField("$modelType", BeanModelType.class)
.method(method -> "$modelType".equals(method.getName()))
.intercept(FieldAccessor.ofField("$modelType"))

// Create the class
.name(proxyClassName).make()
.load(classLoader, ClassLoadingStrategy.Default.WRAPPER)
.getLoaded();

在这里,两个类加载器很重要。首先,这里是 OSGi Bundle ClassLoader (classLoader)。其次,Bundle的类加载器包含TemplateModelProxyHandler类,例如TemplateModelProxyHandler.class.getClassLoader()。 有没有办法在这里使用两个类加载器? 有没有一种简单的方法可以通过 ByteBuddy 实现这一目标?

【问题讨论】:

    标签: java osgi vaadin byte-buddy vaadin-flow


    【解决方案1】:

    查看 Byte Buddy 附带的 MultipleParentClassLoader。它允许您为类加载器指定多个父级并在其中定义一个类。

    【讨论】:

    • 嗨拉斐尔,感谢您的回复。因此,只需将load 方法中的classLoaderMultipleParentClassLoader 交换就可以解决问题吗?以后试试!
    • 理论上是的。
    • 它在实践中也有效,非常感谢Rafael!
    猜你喜欢
    • 2012-07-08
    • 2012-07-27
    • 2014-09-04
    • 2011-12-05
    • 1970-01-01
    • 2016-05-06
    • 1970-01-01
    • 1970-01-01
    • 2016-07-13
    相关资源
    最近更新 更多