0

I have an interface called WordDao, an abstract class impl called WordDaoImpl. And some impl class extends that abstract class.

I use same variable name when I inject them.

ex:

@Component("subjectService")
public class SubjectDaoImpl extends WordDaoImpl;

@Autowired
private WordDao subjectService;

Everything work well before I add feign. my feign client is a interface extends WordDao.

like this:

@FeignClient("Noun")
public interface NounClient extends WordDao;

Now all my @Autowired class are inject feign client. autowired result

I tried to remove "extends WordDao" from my feign client and it work well again, but I don't know why.

My question is: Is feign has top priority when inject? Isn't spring @autowired pick impl class by name(try to match variable and class/Component name)?

min
  • 953
  • 1
  • 11
  • 23

1 Answers1

1

FeignClient beans is set as primary like you define beans with @Primary. Probably that's why FeignClient beans are set with priority. Fortunately it is configurable from spring-cloud-netflix 1.3.0. You can use it with Dalston release.

Please, try to change your code like below.

@FeignClient(name = "Noun", primary = false)
public interface NounClient extends WordDao;

One thing you should be careful is that primary is usually need when you are using FeignClient with fallback implementation. Fallback implementation also should be spring bean, there would exist two implementations - one from FeignClient and the other from fallback.

Hopes this helps.

yongsung.yoon
  • 5,489
  • 28
  • 32
  • Any idea about how to solve two impl problem? I tried use "same variable name" but no luck. spring still complain two impl and fail to start the server – min Jun 01 '17 at 15:41