spring-cloud/spring-cloud-openfeign

@EnableFeignClients does not detect feign bean in multi-module.

young0264 opened this issue · 3 comments

Describe the bug

  1. open feign version
	implementation 'org.springframework.cloud:spring-cloud-starter-openfeign:4.1.1'
  1. It is assumed that the package structure is the same across modules.

Hi, I have discovered issue.
In a multi-module Spring Boot project, when @EnableFeignClients is configured in the main application class, it does not detect Feign clients implementing other modules.

implementation project(':common-lib')

In a situation where a module references a library module like common-lib using implementation project(':common-lib'), the beans are not being detected.(Assuming the module package structure is the same)

However, when explicitly setting the package path in @EnableFeignClients(ex: @EnableFeignClients("org.project")), it successfully scans and registers Feign client beans from other modules.

I'm curious whether this is the intended behavior or if it might be an issue.

If this behavior is not intentional, it would be helpful to document it in the related documentation. (Should I be the one to register it? I also want to be a contributor.)

    // The results will vary depending on whether you use @EnableFeignClients("org.project") or just @EnableFeignClients.
    @Test
    void isThereBeanImplementedMultiModule() {
        String feignBeanName = "alarmCommonFeignClient";
        String[] beanNames = applicationContext.getBeanDefinitionNames();
        for (String beanName : beanNames) {
            boolean contains = beanName.contains(feignBeanName);
            if (contains) {
                assertThat(contains).isEqualTo(true);
            }
        }
    }
# console
beanName: alarmCommonFeignClient.FeignClientSpecification
스크린샷 2024-09-04 13 22 54

Hello @young0264. We have discussed it as a team: this is by design and we're not planning on changing it at this point.

Hello @young0264. We have discussed it as a team: this is by design and we're not planning on changing it at this point.

Thank you for your response. What I'm curious about is, if that's how it was intentionally designed, shouldn't the official documentation mention something like "In order to read Feign beans in a multi-module setup, you need to specify the path directly"? What do you think?

Right, I'll add the missing info to the documentation.