Could not autowire field: private org.optaplanner.core.api.solver.SolverManager

huangapple go评论84阅读模式
英文:

Could not autowire field: private org.optaplanner.core.api.solver.SolverManager

问题

这是我翻译好的内容:

我想在我的 Spring MVC 项目中使用 Optaplanner我遇到了以下异常:`无法自动装配字段private org.optaplanner.core.api.solver.SolverManager`

这是我的服务类

public class ServiceTimeTableImpl implements IServiceTimeTable {

    IDaoTimeTable dao;

    public static final Long SINGLETON_TIME_TABLE_ID = 1L;

    @Autowired
    private SolverManager<TimeTable, Long> solverManager;

    @Autowired
    ScoreManager<TimeTable> scoreManager;

}

这是我的 POM 依赖

<dependency>
    <groupId>org.optaplanner</groupId>
    <artifactId>optaplanner-spring-boot-starter</artifactId>
    <version>7.40.0.Final</version>
</dependency>

完整的异常信息如下

org.springframework.beans.factory.BeanCreationException: 创建 bean名为 'servicetime')失败自动装配依赖项失败嵌套异常为 org.springframework.beans.factory.BeanCreationException: 无法自动装配字段private org.optaplanner.core.api.solver.SolverManager com.nouhaila.timetable.service.ServiceTimeTableImpl.solverManager嵌套异常为 org.springframework.beans.factory.NoSuchBeanDefinitionException: 找不到类型为 [org.optaplanner.core.api.solver.SolverManager] 的合格 bean作为此依赖项的自动装配候选项至少应有 1 个合格的 bean依赖项注解{@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
    ...

(请注意,上述内容只包含翻译的部分,不包括额外的回答或信息。)

英文:

I want to use Optaplanner with my spring mvc project. and I got this exception: Could not autowire field: private org.optaplanner.core.api.solver.SolverManager

this is my service :

public class ServiceTimeTableImpl implements IServiceTimeTable {
IDaoTimeTable dao;
public static final Long SINGLETON_TIME_TABLE_ID = 1L;
@Autowired
private SolverManager&lt;TimeTable, Long&gt; solverManager;
@Autowired
ScoreManager&lt;TimeTable&gt; scoreManager;
}

and this is my pom dependency:

&lt;dependency&gt;
&lt;groupId&gt;org.optaplanner&lt;/groupId&gt;
&lt;artifactId&gt;optaplanner-spring-boot-starter&lt;/artifactId&gt;
&lt;version&gt;7.40.0.Final&lt;/version&gt;
&lt;/dependency&gt;

the hole exception is :

org.springframework.beans.factory.BeanCreationException: Error creating bean with name &#39;servicetime&#39;: Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.optaplanner.core.api.solver.SolverManager com.nouhaila.timetable.service.ServiceTimeTableImpl.solverManager; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.optaplanner.core.api.solver.SolverManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4678)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5139)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
at java.util.concurrent.FutureTask.run(Unknown Source)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(Unknown Source)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:841)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374)
at java.util.concurrent.FutureTask.run(Unknown Source)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(Unknown Source)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:909)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:421)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:930)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.startup.Catalina.start(Catalina.java:738)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:342)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:473)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.optaplanner.core.api.solver.SolverManager com.nouhaila.timetable.service.ServiceTimeTableImpl.solverManager; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.optaplanner.core.api.solver.SolverManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
... 43 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.optaplanner.core.api.solver.SolverManager] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
... 45 more

答案1

得分: 1

这很奇怪,optaplanner-spring-boot-starter应该会自动暴露它。你可以尝试升级到最新版本(7.43.0.Final),其中有一些改进,但我怀疑这是否有帮助。

尝试在OptaPlannerAutoConfiguration中设置断点,以查看是否已激活。请注意,它只会在你使用Spring Boot时才起作用,而不仅仅是Spring。

英文:

That's weird, the optaplanner-spring-boot-starter should automatically expose it. You could try upgrading to the latest (7.43.0.Final) which has a few improvements but I doubt that helps.

Try putting a breakpoint in OptaPlannerAutoConfiguration to see if it is active. Not that it will only work if you use Spring Boot, not just Spring.

huangapple
  • 本文由 发表于 2020年9月14日 00:06:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/63872802.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定