Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

springboot could not found feignclient

ERROR INFO LIKE BELOW:

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

Description:

Field helloAgent in com.example.client.controller.Hello required a bean of 
type 'com.example.common.agent.HelloAgent' that could not be found.

Action:

Consider defining a bean of type 'com.example.common.agent.HelloAgent' in 
your configuration.

project structure:

module: test-client as feignclient caller.

module: test-server as feignclient interface implementation.

module: test-common put all feignclient together.

test-common:

package com.example.common.agent;
@FeignClient("hello")
public interface HelloAgent {
    @GetMapping("/hello")
    String hello(@RequestParam String msg);
}

test-server:(works fine)

package com.example.server.controller;

@RestController
public class Hello implements HelloAgent {
    @Override
    public String hello(@RequestParam String msg) {
        System.out.println("get " + msg);
        return "Hi " + msg;
    }
}

test-client:

package com.example.client.controller;

@RestController
public class Hello {
    @Autowired
    private HelloAgent helloAgent;

    @GetMapping("/test")
    public String test() {
        System.out.println("go");
        String ret = helloAgent.hello("client");
        System.out.println("back " + ret);
        return ret;
    }
}
----------------------------
@EnableEurekaClient
@EnableFeignClients
@SpringBootApplication
@ComponentScan(basePackages = {"com.example.common.agent","com.example.client.controller"})
public class TestClientApplication {
    public static void main(String[] args) {
        SpringApplication.run(TestClientApplication.class, args);
    }
}

Is there anyway to put all feignclient together so that we can manage them gracefully?

Or there is only way to use them redundancy?

THANKS!

like image 817
ajianzheng Avatar asked Jan 16 '18 04:01

ajianzheng


People also ask

What is feignclient in Spring Boot?

FeignClient is a Declarative REST Client in Spring Boot Web Application. Declarative REST Client means you just give the client specification as an Interface and spring boot takes care of the implementation for you.

How to configure client configuration in Spring Boot?

Client configurations such as encoding/decoding, timeout, logging can just be done through property files. Client configurations can be done from Java Configuration file as well. Developed by Netflix. It has great support to work with other spring-boot cloud libraries such as Hystrix, Eureka and Ribbon

How to configure requestinterceptor in Spring Boot?

There are two ways of configuring RequestInterceptor with a spring boot application. In here we can use the same configuration class which we written for above step to add requestinterceptor to set dynamic headers into every and each request foing through feign client in spring boot.

What is declarative REST client in Spring Boot?

Declarative REST Client means you just give the client specification as an Interface and spring boot takes care of the implementation for you. FeignClient is used to consume RESTFul API endpoints exposed by thirdparty or microservice.


1 Answers

Feign doesn't know about @ComponentScan.

Use @EnableFeignClients(basePackages = {"com.example.common.agent","com.example.client.controller"})

like image 136
spencergibb Avatar answered Sep 24 '22 04:09

spencergibb