Cromm
Cromm

Reputation: 352

java.lang.IllegalStateException when creating a ScoreManager on Spring for OptaPlanner

I got the following exception when trying to create a scoreManager :

java.lang.IllegalStateException: The solutionClass (class my.package.MySolution) has been specified as a solution in the configuration, but does not have a @PlanningSolution annotation.

However, the MySolution class does have the @PlanningSolution annotation, and the xml config file used looks like this :

<solver>
   ...
  <solutionClass>my.package.MySolution</solutionClass>
  <entityClass>my.package.MyAssignment</entityClass>
   ...
</solver>

But when calling the SolverFactory.createFromXmlResource like this :

        SolverFactory<MySolution> solverFactory = SolverFactory.createFromXmlResource("solver/myRosteringSolverConfig.xml");

        var scoreManager = ScoreManager.create(solverFactory);

I got the mentioned exception. Which does not make sense, because 1) the config use the same solutionClass as used by the SolverFactory and 2) the class is annotated...

Upvotes: 1

Views: 518

Answers (1)

Geoffrey De Smet
Geoffrey De Smet

Reputation: 27312

The class cast exception is probably because it's loading the same @Planningsolution class from two different jars.

Use optaplanner-spring-boot-starter to avoid such classloading issues.

Upvotes: 1

Related Questions