0

I am trying to set communication between micro services using eureka and feign client. Eureka is working fine and every micro service is registering themselves. But when I add a feign client it gives me an abstract method error.

I am using eureka and feign for the first time, so please tell me if I am doing something wrong.

I have two services user and academics. And I want to access a method from academics in user service.

user/pom.xml and academics/pom.xml is same

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.5.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>sgsits.cse.dis</groupId>
<artifactId>user</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>user</name>
<description>User Service</description>

<properties>
    <java.version>1.8</java.version>
    <spring-cloud.version>Greenwich.RC2</spring-cloud.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>

</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
    </repository>
</repositories>

</project>

academics/AcademicsApplication.java

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class AcademicsApplication {

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

user/AcademicsService.java

@FeignClient(name="academics", url = "https://localhost:8080")
 public interface AcademicsService {

@RequestMapping(value = "/student/subjectList", method = RequestMethod.GET)
public List<Scheme> getSubjectList();

}

user/UserApplication.java AttendanceController is the class where I am using the academicsService subjectList method

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class UserApplication {

public static void main(String[] args) {

    ConfigurableApplicationContext ctx = SpringApplication.run(UserApplication.class, args);
    AttendanceController attendanceController = ctx.getBean(AttendanceController.class);
    System.out.println(attendanceController);
    attendanceController.getAttendancePercentage();     
}

@Bean
public AttendanceController attendanceController()
{
    return new AttendanceController();
}
}
Divyani Garg
  • 138
  • 1
  • 3
  • 15
  • 2
    Use the correct version. Fincley is for Spring Boot 2.0, Greenwich for Spring Boot 2.1 (and it isn't final yet as well). – M. Deinum Jan 21 '19 at 19:05
  • Hey thanks, this removed the abstract method error and started giving me another error regarding bean creation. . Error creating bean with name 'attendanceController': Unsatisfied dependency expressed through field 'academicsService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sgsits.cse.dis.user.feign.AcademicsService': FactoryBean threw exception on object creation; nested exception is java.lang.NoClassDefFoundError: feign/Request$HttpMethod – Divyani Garg Jan 21 '19 at 19:23

0 Answers0