OptaPlanner - 在 Spring 引导应用程序中找不到 SolverManager 和 SolverManager 类型的 beans

OptaPlanner - No beans of SolverManager and SolverManager types found in Spring Boot application

我添加了 optaplanner-spring-boot-starterSpring Boot 应用程序的依赖,但是注入的 SolverManagerScoreManager beans 没有在 Intellij.

上找到
***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method myBusinessBeanAPI in 
mypackage.MyRestResource required a bean 
of type 'org.optaplanner.core.api.solver.SolverManager' that could not be found.


Action:

Consider defining a bean of type 'org.optaplanner.core.api.solver.SolverManager' in your 
configuration.

我该如何解决这个问题?

documentation 中,它说在 Quarkus 和 Spring Boot 中,SolverManager 实例会自动注入到您的代码中。否则,使用 create(... ) 方法构建一个 SolverManager 实例:

SolverConfig solverConfig = SolverConfig.createFromXmlResource(".../cloudBalancingSolverConfig.xml");
SolverManager<CloudBalance, UUID> solverManager = SolverManager.create(solverConfig, new SolverManagerConfig());

所以你可能没有正确导入依赖项。 如果你正在使用 maven 并使用依赖管理配置:

<dependencies>
...
<dependency>
            <groupId>org.optaplanner</groupId>
            <artifactId>optaplanner-spring-boot-starter</artifactId>
</dependency>
...
</dependencies>
<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.optaplanner</groupId>
                <artifactId>optaplanner-spring-boot-starter</artifactId>
                <version>7.38.0.Final</version>
            </dependency>
        </dependencies>
</dependencyManagement>

如果您正在使用 gradle:

compile 'org.optaplanner:optaplanner-spring-boot-starter:7.38.0.Final'