我正在修改 optaplanner-webexamples vrp。所以我有点使用 spring-boot,我编辑了一些模型等。但是在运行 solve 时,它会在 VehicleRoutingSolution 类上产生 ClassCastExceptionjava.lang.ClassCastException: id.co.asyst.vrp.core.solution.VehicleRoutingSolution cannot be cast to id.co.asyst.vrp.core.solution.VehicleRoutingSolutionat 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 获取的大部分代码对模型进行了很少的修改。大多只是表关系。
3 回答
慕后森
TA贡献1802条经验 获得超5个赞
我想出的最佳解决方案是使用Spring Boot 文档中推荐的上下文类加载器。使用上下文类加载器作为 的第二个参数SolverFactory.createFromXmlResource()。例如:
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
SolverFactory<VehicleRoutingSolution> sf = SolverFactory.createFromXmlResource(
"org/optaplanner/examples/vehiclerouting/solver/vehicleRoutingSolverConfig.xml",
classLoader
);
与我之前的回答一样,这与开发人员工具一起使用,因此您可以留spring-boot-devtools在 POM 中并继续使用自动重启功能。
添加回答
举报
0/150
提交
取消