Wildfly-Camel 12 中的 Groovy JsonBuilder 类加载错误



我在驼峰路由内的Groovy代码中调用JsonBuilder.toString((。这条骆驼路线在Widlfly Camel 12.0内部运行。代码如下所示:

def builder = new JsonBuilder()
builder {
'myField': myFieldVal
}
return builder.toString()

builder.toString(( 方法调用产生以下错误:

Caused by: java.lang.NoClassDefFoundError: Could not initialize class 
groovy.json.internal.FastStringUtils

但是我确实在pom中正确提到了依赖项.xml如下所示:

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-groovy</artifactId>
<scope>provided</scope>
</dependency>

我还尝试添加此额外的依赖项来解决问题:

<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-json</artifactId>       
<version>2.4.13</version>
</dependency>

但我仍然不断得到上述例外。但是,当我使用 camel-maven-plugin 运行相同的 Camel 代码时,没有将其部署到 Wildfly 中,它运行完美。

有人可以帮忙吗?

提前谢谢。

我认为问题是模块org.apache.camel.script.groovy无法访问sun.misc.Unsafe。所以我在modules/system/layers/fuse/org/apache/camel/script/groovy/main/module.xml中添加了以下模块依赖项。

<module name="sun.jdk">
<imports>
<include path="sun/misc/Unsafe"/>
</imports>
</module>

你的例子后来对我有用。

最新更新