首页 > 解决方案 > 添加feign客户端后如何修复抽象方法错误

问题描述

我正在尝试使用 eureka 和 feign 客户端设置微服务之间的通信。Eureka 工作正常,每个微服务都在注册自己。但是当我添加一个假装客户端时,它给了我一个抽象方法错误。

我是第一次使用 eureka 和 feign,所以如果我做错了什么,请告诉我。

我有两个服务用户和学者。我想从用户服务中的学者那里获得一种方法。

user/pom.xml 和 Academics/pom.xml 相同

<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>

学术/学术应用程序.java

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class AcademicsApplication {

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

用户/学术服务.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 是我使用 AcademicsService subjectList 方法的类

@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();
}
}

标签: javaspring-bootfeign

解决方案


推荐阅读