可以在Spring Boot OptaPlanner中使用多个`@PlanningSolution`类和多个`SolverManager`吗?

huangapple go评论76阅读模式
英文:

can we use multiple @PlanningSolution classes and multiple SolverManager in Springboot optaplanner

问题

使用optaplanner-spring-boot-starter的Spring Boot应用程序,对于使用单个Planning Solution和SolverManager正常工作的CloudBalancing问题解决方案,类似于https://github.com/DuncanDoyle/optaplanner-sbs-cloud-balancing/tree/master/optaplanner-sbs,但是当定义并且通过SolverManager调用多个Planning Solution时,会抛出错误:

> Caused by:
> org.springframework.beans.factory.UnsatisfiedDependencyException:
> 在类路径resource [org/optaplanner/spring/boot/autoconfigure/OptaPlannerAutoConfiguration.class] 中定义的名为'solverFactory'的bean创建时出错:通过方法'solverFactory'参数0传递的不满意的依赖项;嵌套异常是
> org.springframework.beans.factory.BeanCreationException: 在类路径resource [org/optaplanner/spring/boot/autoconfigure/OptaPlannerAutoConfiguration.class] 中定义的名为'solverConfig'的bean创建时出错:通过工厂方法实例化Bean;嵌套异常是
> org.springframework.beans.BeanInstantiationException: 无法实例化[org.optaplanner.core.config.solver.SolverConfig]:工厂方法'solverConfig'抛出异常;嵌套异常是
> java.lang.IllegalStateException:找到多个带有@PlanningSolution注解的类([class com.test.model.PRCaseAssignment,class com.test.model.CaseAssignment])。

我们如何定义多个@PlanningSolution类并且通过solverManager进行调用?是否需要注释任何类型的Qualifiers?非常感谢您的帮助。谢谢。

英文:

For Springboot application using optaplanner-spring-boot-starter, the cloudbalancing problem solution works fine with one planning solution and solverManager similar to
https://github.com/DuncanDoyle/optaplanner-sbs-cloud-balancing/tree/master/optaplanner-sbs , but when multiple planning solutions are defined and called using a solverManager it throws an error

> Caused by:
> org.springframework.beans.factory.UnsatisfiedDependencyException:
> Error creating bean with name 'solverFactory' defined in class path
> resource
> [org/optaplanner/spring/boot/autoconfigure/OptaPlannerAutoConfiguration.class]:
> Unsatisfied dependency expressed through method 'solverFactory'
> parameter 0; nested exception is
> org.springframework.beans.factory.BeanCreationException: Error
> creating bean with name 'solverConfig' defined in class path resource
> [org/optaplanner/spring/boot/autoconfigure/OptaPlannerAutoConfiguration.class]:
> Bean instantiation via factory method failed; nested exception is
> org.springframework.beans.BeanInstantiationException: Failed to
> instantiate [org.optaplanner.core.config.solver.SolverConfig]: Factory
> method 'solverConfig' threw exception; nested exception is
> java.lang.IllegalStateException: Multiple classes ([class
> com.test.model.PRCaseAssignment, class
> com.test.model.CaseAssignment]) found with a
> @PlanningSolution annotation.

How can we define multiple @PlanningSolution classes and call using the solverManager, are there any kind of Qualifiers which needs to be annotated? Any help is appreciated. Thanks.

答案1

得分: 1

我可以问一下,拥有多个解决方案类的用例是什么?

optaplanner-spring-boot-starter 仅支持单个求解器配置,因此仅支持单个解决方案类。SolverManager API 也是如此:您可以将多个计划问题提交给 SolverManager,但它们必须是相同类型(解决方案类)并共享相同的求解器配置。要提交不同类型的计划问题,您必须创建 SolverManager 的新实例。请参阅文档,了解如何手动创建 SolverManager 实例。

英文:

May I ask what is the use case for having multiple solution classes?

The optaplanner-spring-boot-starter supports only a single solver configuration and thus only a single solution class. So does the SolverManager API: you can submit multiple planning problems to the SolverManager, but they have to be of the same type (solution class) and share the same solver configuration. To submit a planning problem of a different type, you have to create a new instance of the SolverManager. See the documentation on how to create an instance of the SolverManager manually.

huangapple
  • 本文由 发表于 2020年9月3日 10:26:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/63715928.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定