提问人:jiayukkkzheng 提问时间:11/30/2022 更新时间:11/30/2022 访问量:90
为什么 java.lang.NullPointerException 在 spring boot 中?
Why java.lang.NullPointerException in spring boot?
问:
它不适用于 SolverManager,控制器中的代码:
UUID problemId = UUID.randomUUID();
SolverConfig solverConfig = SolverConfig.createFromXmlResource(Args.SOLVER_CONFIG);
System.out.println(solverConfig.getEntityClassList());
SolverManager<VehicleRoutingSolution, UUID> solverManager = SolverManager.create(solverConfig, new SolverManagerConfig());
SolverJob<VehicleRoutingSolution, UUID> solverJob = solverManager.solve(problemId, unsolvedVRP);
try {
VehicleRoutingSolution finalBestSolution = solverJob.getFinalBestSolution();
System.out.println(finalBestSolution);
} catch (InterruptedException | ExecutionException e) {
throw new IllegalStateException("Solving failed.", e);
}
...
控制台输出:
[null, null, null]
15:56:46.845 [-8090-exec-1] ERROR Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException: null
at org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor.sortEntityClassList(SolutionDescriptor.java:123)
at org.optaplanner.core.impl.domain.solution.descriptor.SolutionDescriptor.buildSolutionDescriptor(SolutionDescriptor.java:108)
at org.optaplanner.core.impl.solver.DefaultSolverFactory.buildSolutionDescriptor(DefaultSolverFactory.java:146)
at org.optaplanner.core.impl.solver.DefaultSolverFactory.<init>(DefaultSolverFactory.java:69)
at org.optaplanner.core.api.solver.SolverFactory.create(SolverFactory.java:106)
at org.optaplanner.core.api.solver.SolverManager.create(SolverManager.java:72)
at com.optTool.controller.CalcController.calculate(CalcController.java:82)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
...
然后,我尝试使用optaplanner-spring-boot-starter集成xml配置,但失败了!
YML的:
optaplanner:
solver:
termination:
spent-limit: 3s
unimproved-spent-limit: 5s
solver-config-xml: com/optTool/core/vehiclerouting/vehicleRoutingSolverConfig.xml
启动时输出:
16:03:04.948 [estartedMain] 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.BeanCreationException: Error creating bean with name 'solverFactory' 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.api.solver.SolverFactory]: Factory method 'solverFactory' threw exception; nested exception is java.lang.NullPointerException
16:03:05.002 [estartedMain] 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.BeanCreationException: Error creating bean with name 'solverFactory' 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.api.solver.SolverFactory]: Factory method 'solverFactory' threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800)
答: 暂无答案
评论