我正在尝试使用eureka和伪装客户端设置微服务之间的通信。尤里卡(Eureka)工作正常,每个微服务都在注册自己。但是,当我添加一个伪装客户端时,它给了我一个抽象方法错误。
我第一次使用尤里卡和假装,所以请告诉我是否做错了事。
我有两个服务用户和学者。我想从用户服务的学者那里访问一种方法。
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>
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是我正在使用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();
}
}