The attribute field basePackages annotated with @EnableFeignClients in Spring Cloud

Under normal circumstances, we add the @EnableFeignClients annotation to the startup class to indicate that there are places in the current application service (we call it service A) that we want to reference interfaces in other application services (we call it service B). If service B can be started separately and registered to the registry, we only need to add the @EnableFeignClients annotation to the startup class of service A ; if service B is not started separately, it is introduced to service A in the form of a Jar package , When service A starts, it will not actively load the interface annotated with @FeignClient in service B and automatically generate bean objects , so that we can introduce and use it in the Controller class in service A in the following way B service in marked @FeignClient annotation interface is being given the

import com.bc.product.client.ProductClient;

@RestController
public class ClientController {

    @Autowired
    private ProductClient productClient;

    ...
}

At this time, you need to use the basePackages attribute field to specify that application A needs to scan the package path of the interface marked with @FeignClient annotation in service B when application A starts.

@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients(basePackages = {"com.bc.product.client"})
public class OrderApplication {

	public static void main(String[] args) {
		SpringApplication.run(OrderApplication.class, args);
	}

}

 

Guess you like

Origin blog.csdn.net/y_bccl27/article/details/108930726