我在 Camel 路由内的 Groovy 代码中调用 JsonBuilder.toString() 。这条 Camel 路线在 Widflly 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>
你的例子后来对我有用。
关于apache-camel - Wildfly-Camel 12 中的 Groovy JsonBuilder 类加载错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50459736/