我有一个小的OptaPlanner应用程序,在没有Spring Boot的情况下工作得很好。我基本上改变了云平衡opta应用的用途。我还包含了所有Spring Boot依赖项。POM父对象是spring-boot-starter-parent。我将optaplanner-spring-boot-starter作为依赖项。
通过这个设置,我仍然可以毫无问题地运行opta应用程序。然后我在项目中添加了一个Spring Boot应用程序。应用程序如下所示:
package org.optaplanner.examples;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}不幸的是,当我运行这个spring boot应用程序时,我得到了以下错误异常:
Maybe your @ConstraintProvider annotated class is not in a subpackage of your @SpringBootApplication annotated class's package.
Maybe move your constraint provider class to your application class's (sub)package.我有一个包含所有drool规则的constraints.drl文件。它位于src/main/resources/org/optaplanner/examples下;据我所知,它与spring boot应用程序在同一个包中。甚至在constraints.drl文件中,我也有以下声明:
package org.optaplanner.examples;
dialect "java"所以我有点困惑。下面是完整的例外。我必须注意,我有云平衡示例附带的求解器: cloudBalancingSolverConfig.xml。
有什么建议吗?
2:27:47.538 [main ] WARN Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'solverManager' defined in class path resource [org/optaplanner/spring/boot/autoconfigure/OptaPlannerAutoConfiguration.class]: Unsatisfied dependency expressed through method 'solverManager' parameter 0; nested exception is 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: No classes found that implement EasyScoreCalculator, ConstraintProvider or IncrementalScoreCalculator, nor a constraints.drl resource.
Maybe your @ConstraintProvider annotated class is not in a subpackage of your @SpringBootApplication annotated class's package.
Maybe move your constraint provider class to your application class's (sub)package.
12:27:47.554 [main ] ERROR Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'solverManager' defined in class path resource [org/optaplanner/spring/boot/autoconfigure/OptaPlannerAutoConfiguration.class]: Unsatisfied dependency expressed through method 'solverManager' parameter 0; nested exception is 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: No classes found that implement EasyScoreCalculator, ConstraintProvider or IncrementalScoreCalculator, nor a constraints.drl resource.
Maybe your @ConstraintProvider annotated class is not in a subpackage of your @SpringBootApplication annotated class's package.
Maybe move your constraint provider class to your application class's (sub)package.
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:797)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:538)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1176)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at org.optaplanner.examples.Application.main(Application.java:9)
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: No classes found that implement EasyScoreCalculator, ConstraintProvider or IncrementalScoreCalculator, nor a constraints.drl resource.发布于 2020-09-25 14:58:56
在错误消息中向右滚动。spring boot is log隐藏了错误消息的第一部分:
No classes found that implement EasyScoreCalculator, ConstraintProvider or IncrementalScoreCalculator, nor a constraints.drl resource.
Maybe your @ConstraintProvider annotated class is not in a subpackage of your @SpringBootApplication annotated class's package.
Maybe move your constraint provider class to your application class's (sub)package.这意味着它看不到constraints.drl。如果你有一个solverConfig.xml,它可能也看不到这一点。
修复:将fooSolverConfig.xml移到src/main/resources/solverConfig.xml或使用application.properties来声明它所在的位置。该求解器配置说明您的scoreRules.drl在哪里。您还可以删除该<scoreDrl>行,只需将您的fooScoreRules.drl作为src/main/resources/constraints.drl
显然,错误消息有点(也是?)偏向于ConstraintStreams :)
https://stackoverflow.com/questions/64050728
复制相似问题