本文介绍了将自定义 Forager 与 OptaPlanner 一起使用时的 XStream ForbiddenClassException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将 optaplanner 版本从 7.0.0 版升级到了 7.4.1 版.我使用在配置文件中声明的自定义 Forager,如下所示:

...<forager class="com.mycompany.MyCustomForagerConfig"><acceptedCountLimit>100</acceptedCountLimit></觅食者>...

使用以前的 OptaPlanner 版本一切正常,但升级后我在 OptaPlanner 读取 config.xml 文件时遇到问题:

---- 调试信息----原因异常:com.thoughtworks.xstream.security.ForbiddenClassException原因消息:com.mycompany.MyCustomForagerConfig类:org.optaplanner.core.config.localsearch.LocalSearchPhaseConfig必需类型:org.optaplanner.core.config.localsearch.LocalSearchPhaseConfig转换器类型:com.thoughtworks.xstream.converters.reflection.ReflectionConverter行号:137类[1]:org.optaplanner.core.config.solver.SolverConfig版本:1.4.10-------------------------------在 com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:79)在 com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:70)…

似乎与这个问题有些相关https://issues.jboss.org/browse/PLANNER-896 (resolved) for the latest version (7.5.0), 所以我尝试升级但问题仍然存在.

谢谢.

解决方案

在 MyCustomForagerConfig 上添加一个 @XStreamAlias 并执行如下操作:

((XStreamXmlSolverFactory)solverFactory).addXStreamAnnotations(MyCustomForagerConfig.class);

出于好奇,您为什么需要自定义觅食器?它是否添加了 OptaPlanner 应该开箱即用的功能?

I recently upgraded optaplanner version from version 7.0.0 to version 7.4.1. I use a custom Forager declared in the config file like this:

...
<forager class="com.mycompany.MyCustomForagerConfig">
            <acceptedCountLimit>100</acceptedCountLimit>
</forager>
...

Everything worked without hassle with the previous OptaPlanner version, but after the upgrade I got a problem while OptaPlanner reads the config.xml file:

---- Debugging information ----
cause-exception     : com.thoughtworks.xstream.security.ForbiddenClassException
cause-message       : com.mycompany.MyCustomForagerConfig
class               : org.optaplanner.core.config.localsearch.LocalSearchPhaseConfig
required-type       : org.optaplanner.core.config.localsearch.LocalSearchPhaseConfig
converter-type      : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
line number         : 137
class[1]            : org.optaplanner.core.config.solver.SolverConfig
version             : 1.4.10
-------------------------------
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:79)
    at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:70)
    …

It seems somewhat related to this issue https://issues.jboss.org/browse/PLANNER-896 (resolved) for the latest version (7.5.0), so I tried to upgrade but the problem persists.

Thanks.

解决方案

Add an @XStreamAlias on your MyCustomForagerConfig and do something like this:

((XStreamXmlSolverFactory) solverFactory).addXStreamAnnotations(MyCustomForagerConfig.class);

Out of curiosity, why do you need a custom forager? Does it add a functionality that OptaPlanner should do out of the box?

这篇关于将自定义 Forager 与 OptaPlanner 一起使用时的 XStream ForbiddenClassException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-09 17:06