DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Distributed Tracing System (Spring Cloud Sleuth + OpenZipkin)
  • Component Tests for Spring Cloud Microservices
  • A Robust Distributed Payment Network With Enchanted Audit Functionality - Part 2: Spring Boot, Axon, and Implementation
  • 7 Microservices Best Practices for Developers

Trending

  • Building Enterprise-Ready Landing Zones: Beyond the Initial Setup
  • Revolutionizing Financial Monitoring: Building a Team Dashboard With OpenObserve
  • AWS to Azure Migration: A Cloudy Journey of Challenges and Triumphs
  • Why Database Migrations Take Months and How to Speed Them Up
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Manual Creation of Feign Clients in Spring Cloud

Manual Creation of Feign Clients in Spring Cloud

Learn about the process behind manually building Feign clients to operate in the Spring Cloud framework.

By 
Ryan Baxter user avatar
Ryan Baxter
·
Nov. 20, 16 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
17.7K Views

Join the DZone community and get the full member experience.

Join For Free
If you want something done right, you have to do it yourself

Have you ever heard the saying above? Sometimes it is true even when writing code.

While Spring Cloud makes it extremely easy to create Feign Clients with its use of annotations, sometimes you just have to bite the bullet and create them yourselves. I would say the 90% of the time, the combination of annotations and custom configuration will be good enough for most use cases. Sometimes, however, you run into use cases where that just won’t do. In these cases it would be good to have full control over how you create your Feign clients.

Recently I added some documentation to the Spring Cloud docs that demonstrates exactly how you would do this. Essentially you use the same APIs as you would if you were just using vanilla Feign. Below is the example taken from the Spring Cloud docs.

@Import(FeignClientsConfiguration.class) 
class FooController { 
  private FooClient fooClient; 
  private FooClient adminClient; 

  @Autowired public FooController( ResponseEntityDecoder decoder, SpringEncoder encoder, Client client) { 
    this.fooClient = Feign.builder().client(client) 
      .encoder(encoder) 
      .decoder(decoder) 
      .requestInterceptor(new BasicAuthRequestInterceptor("user", "user")) 
      .target(FooClient.class, "http://PROD-SVC"); 

    this.adminClient = Feign.builder().client(client) 
      .encoder(encoder) 
      .decoder(decoder) 
      .requestInterceptor(new BasicAuthRequestInterceptor("admin", "admin")) 
      .target(FooClient.class, "http://PROD-SVC"); 
  } 
} 

In this example, we are creating two Feign Clients from the same interface, FooClient.class, which are using two different request interceptors. Doing this with the @FeignClient annotation plus configuration would not be possible, so in this case, we need to create the clients using the Feign APIs.

For a more in-depth look at the code, check out this GitHub repo.

Spring Cloud Spring Framework

Published at DZone with permission of Ryan Baxter, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Distributed Tracing System (Spring Cloud Sleuth + OpenZipkin)
  • Component Tests for Spring Cloud Microservices
  • A Robust Distributed Payment Network With Enchanted Audit Functionality - Part 2: Spring Boot, Axon, and Implementation
  • 7 Microservices Best Practices for Developers

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!