Billy Billy
Billy Billy

Reputation: 523

Spring Boot complaining about OptaPlanner

I have a small OptaPlanner app that works great without Spring Boot. I basically repurposed the cloud balancing opta app. I also included all Spring Boot dependencies. The POM parent is spring-boot-starter-parent. And I have optaplanner-spring-boot-starter as dependency.

With this setup, I am still able to run the opta app without problem. Then I added a Spring Boot app to the project. The app is as follows:

package org.optaplanner.examples;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
}
}

Unfortunately, when I run this spring boot app, I get following error exception:

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.

I have a a constraints.drl file that contains all drool rules. And it is located under src/main/resources/org/optaplanner/examples; From what i can see, it is in the same package as the spring boot app. And even inside the constraints.drl file, I have following declaration:

package org.optaplanner.examples;
  dialect "java"

So I am a little confused. Below is the full exception.I must note that I have the solver that comes with the cloud balancung example: cloudBalancingSolverConfig.xml.

Any suggestion?

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.

Upvotes: 0

Views: 775

Answers (1)

Geoffrey De Smet
Geoffrey De Smet

Reputation: 27312

Scroll to the right in your error message. The spring boot is log is hiding the first part of the error message:

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.

That means it's not seeing the constraints.drl. If you have a solverConfig.xml, its probably not seeing that too.

Fix: move your fooSolverConfig.xml to src/main/resources/solverConfig.xml or use the application.properties to state where it is. That solver config states where your scoreRules.drl is. You can also remove that <scoreDrl>line, and just put your fooScoreRules.drl as src/main/resources/constraints.drl

Clearly the error message is a bit (too?) biased for ConstraintStreams :)

Upvotes: 3

Related Questions