Skip to content

Feign Client Configuration Issue: Unable to Dynamically Use Service Name as Host in Eureka Setup #1

@DevRuibin

Description

@DevRuibin
package com.alibou.school.client;

import com.alibou.school.Student;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@FeignClient(name = "student-service", url = "${application.config.students-url}")
public interface StudentClient {

    @GetMapping("/school/{school-id}")
    List<Student> findAllStudentsBySchool(@PathVariable("school-id") Integer schoolId);
}

Issue Description:

I've encountered an issue with my Feign client setup when working with a service registered in Eureka. The current configuration uses the url attribute to specify the endpoint, which feels like hardcoding and lacks the elegance of using the service name as the host.

Desired Outcome:

I want to configure the Feign client to dynamically use the service name registered in Eureka without specifying the URL directly. However, when attempting to remove the url attribute, the framework defaults to accessing the resource on port 80, despite setting server.port=8090 in the configuration file of the student service.

Questions:

  1. Is there a more elegant way to configure the Feign client to use the service name as the host without hardcoding the URL?
  2. How can I ensure that the Feign client uses the correct port specified in the configuration file of the student service rather than defaulting to port 80?

Any assistance or guidance on resolving this issue would be greatly appreciated. Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions