Solver.solve 上发生 ClassCastException

我正在修改 optaplanner-webexamples vrp。所以我有点使用 spring-boot,我编辑了一些模型等。


但是在运行 solve 时,它会在 VehicleRoutingSolution 类上产生 ClassCastException


java.lang.ClassCastException: id.co.asyst.vrp.core.solution.VehicleRoutingSolution cannot be cast to id.co.asyst.vrp.core.solution.VehicleRoutingSolution

at org.optaplanner.core.impl.domain.common.accessor.LambdaBeanPropertyMemberAccessor.executeGetter(LambdaBeanPropertyMemberAccessor.java:120)

at org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor.getScore(SolutionDescriptor.java:1071)

at org.optaplanner.core.impl.score.director.AbstractScoreDirector.cloneSolution(AbstractScoreDirector.java:212)

at org.optaplanner.core.impl.solver.scope.DefaultSolverScope.setWorkingSolutionFromBestSolution(DefaultSolverScope.java:230)

at org.optaplanner.core.impl.solver.AbstractSolver.solvingStarted(AbstractSolver.java:75)

at org.optaplanner.core.impl.solver.DefaultSolver.solvingStarted(DefaultSolver.java:210)

at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:190)

at id.co.asyst.vrp.rest.cdi.VehicleRoutingSolverManager.lambda$solve$1(VehicleRoutingSolverManager.java:105)

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)

at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)

at java.util.concurrent.FutureTask.run(FutureTask.java)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

at java.lang.Thread.run(Thread.java:748)

我哪里做错了?我直接从 optaplanner-webexamples 获取的大部分代码对模型进行了很少的修改。大多只是表关系。


回首忆惘然
浏览 152回答 3
3回答

Qyouu

原来是因为 spring-boot-devtools。在我从pom.xml它移除它之后它工作得很好

慕后森

我想出的最佳解决方案是使用Spring Boot 文档中推荐的上下文类加载器。使用上下文类加载器作为 的第二个参数SolverFactory.createFromXmlResource()。例如:ClassLoader classLoader = Thread.currentThread().getContextClassLoader();SolverFactory<VehicleRoutingSolution> sf = SolverFactory.createFromXmlResource(&nbsp; &nbsp; &nbsp; &nbsp; "org/optaplanner/examples/vehiclerouting/solver/vehicleRoutingSolverConfig.xml",&nbsp; &nbsp; &nbsp; &nbsp; classLoader);与我之前的回答一样,这与开发人员工具一起使用,因此您可以留spring-boot-devtools在 POM 中并继续使用自动重启功能。

尚方宝剑之说

请在此处查看我的回答以获取更多详细信息。您必须检查重复出现的位置:System.out.println(TheGhostClass.class.getProtectionDomain().getCodeSource().getLocation());
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java