whuzjn 2020-06-15 16:09 采纳率: 0%
浏览 2203

Springboot覆盖引用jar包中的类,在启动时报找不到bean异常

我在A工程中引入了B.jar(由B工程执行maven-install打包而来),使用了B中的Service,我想在A工程中重写B工程中的“CustomerButtonService”类,但是将B工程中的“CustomerButtonService”类拷贝到A工程中后,在启动A工程时,初始化“customerButtonController”时报了下面的异常,在线求救中。
2020-06-15 15:46:08,761 [restartedMain] WARN o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext 557 - Exception encountered dur
ing context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating be
an with name 'customerButtonController': Unsatisfied dependency expressed through field 'customerButtonService'; nested exception is org.spr
ingframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.test.os.management.customerButton.service.Custo
merButtonService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.b
eans.factory.annotation.Autowired(required=true)}


APPLICATION FAILED TO START


Description:

Field customerButtonService in com.test.os.management.customerButton.controller.CustomerButtonController required a bean of type 'com.test.os.management.customerButton.service.CustomerButtonService' that could not be found.

Action:

Consider defining a bean of type 'com.test.os.management.customerButton.service.CustomerButtonService' in your configuration.

谢谢“Timor_D”的回答,我按照您的建议查了一遍,都没有问题,不过在检查过程中发现我A工程的pom.xml文件里引入了【devtools】工具,去掉下面这个引用就好了

    <!-- spring boot devtools -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
  • 写回答

2条回答 默认 最新

  • Timor_D 2020-06-15 16:24
    关注

    service上面加@service注解了吗?

    评论

报告相同问题?