Java Openfeign&x2B;SpringCloud:字段需要找不到类型的bean

Java Openfeign&x2B;SpringCloud:字段需要找不到类型的bean,java,rest,spring-boot,autowired,openfeign,Java,Rest,Spring Boot,Autowired,Openfeign,我对spring和openfeign有一个问题,我想你可以帮助我 我有一个pom文件,如下所示: 4.0.0 xx.yyy 成分 1.0.0 成分 1.8 3.1.1 3.6.7 格林威治 org.springframework.boot spring启动程序父级 2.1.10.发布 org.springframework.boot 弹簧靴起动器执行器 org.springframework.boot 弹簧启动机amqp org.springframework.boot SpringBootS

我对spring和openfeign有一个问题,我想你可以帮助我

我有一个pom文件,如下所示:


4.0.0
xx.yyy
成分
1.0.0
成分
1.8
3.1.1
3.6.7
格林威治
org.springframework.boot
spring启动程序父级
2.1.10.发布
org.springframework.boot
弹簧靴起动器执行器
org.springframework.boot
弹簧启动机amqp
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
弹簧启动机tomcat
org.springframework.boot
弹簧靴起动器码头
org.springframework.cloud
SpringCloudStarter配置
org.springframework.cloud
春季云启动程序
......
org.springframework.cloud
spring云依赖关系
${spring cloud.version}
聚甲醛
进口
......
我在main类中声明了以下配置:

@SpringBootApplication(scanBasePackages={“xx.yyy”,“xx.yyy.rest.client”},exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class})
@使能同步
@导入({P2OrchestratorApplicationConfig.class})
公共类P2OrchestratorApplication{
公共静态void main(字符串[]args){
run(P2OrchestratorApplication.class,args);
}
}
我有一个自定义的外部配置类:


@Configuration
@EnableFeignClients()
@ImportAutoConfiguration({FeignAutoConfiguration.class})
public class FeignConfig {

    @Bean
    public OkHttpClient client() {
        return new OkHttpClient();
    }

    @Bean
    public Logger.Level feignLoggerLevel() {
        return Logger.Level.FULL;
    }

    @Bean
    public Contract feignContract() {
        return new feign.Contract.Default();
    }
}
我有一个开放的外国客户,如下所示:

@FeignClient(name="legacyClient", value = "legacyClient", url = "${uri.microservice.legacy}", configuration = FeignConfig.class)
public interface LegacyClient {

    @PatchMapping(value = "/legacy/xxx/cleanLine/{authorizationCode}", produces = { MediaType.APPLICATION_JSON_VALUE })
    public ResponseEntity<Boolean> cleanLine(@PathVariable("authorizationCode") Long authorizationCode, @RequestParam(required = true) Long lineNumber);


}
但应用程序给了我下一条信息:

***************************
APPLICATION FAILED TO START
***************************

Description:

Field legacyClient in xxx.yyy.p2.structure.P2ProcessAlgorithm required a bean of type 'xxx.yyy.rest.client.LegacyClient' that could not be found.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)
    - @org.springframework.beans.factory.annotation.Qualifier(value=p2AsyncOrchestratorService)


Action:

Consider defining a bean of type 'xxx.yyy.rest.client.LegacyClient' in your configuration.
我尝试了几种配置,但我无法使openfeign客户端成为P2ProcessAlgorithm类中可识别的bean

你知道吗


提前感谢

以下几点可能会有所帮助:

首先: 为什么要使用限定符将
LegacyClient
bean注入到您的服务中?有很多吗?一般来说,接口应该包装到代理中,并作为单个bean放入应用程序上下文中,因此在我的理解中,这里不需要限定符

另一个关切:

似乎未处理
@FeignClient
注释。因此,不会创建代理。为了检查这一点,在配置中放置一个断点
FeignConfig
some of beans/创建一个no-op构造函数,并检查它是否被调用(或者可以放置日志消息以查看它是否工作)


您尚未发布包结构,但包扫描机制可能未找到此配置,因此未创建此配置。

首先感谢您的回复

我回答了你的第一个问题, 是的,这只是一种习惯。我可以毫无问题地消除它。不再有bean占用同一接口。这不是问题

回应你的第二个评论,你是绝对正确的

将生成器添加到FeignConfig配置类。添加日志和断点,不要停在那里

附上一个ss的包结构,看看你是否可以帮我检测我的问题

  • 在ms.config包中,我有一个假配置类
  • 在rest.client包中,我拥有所有的接口
  • 在ms包中,是带有符号SpringBootApplication的主类
  • 在ms.p2.structure包中,是调用外部客户端的类
事先非常感谢

***************************
APPLICATION FAILED TO START
***************************

Description:

Field legacyClient in xxx.yyy.p2.structure.P2ProcessAlgorithm required a bean of type 'xxx.yyy.rest.client.LegacyClient' that could not be found.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)
    - @org.springframework.beans.factory.annotation.Qualifier(value=p2AsyncOrchestratorService)


Action:

Consider defining a bean of type 'xxx.yyy.rest.client.LegacyClient' in your configuration.