1.定义父接口:
package cn.edu.tju.service;
import org.springframework.web.bind.annotation.RequestMapping;
public interface FatherInterface {
@RequestMapping("/test")
String getTime();
@RequestMapping("/hello")
String getGreeting();
}
2.定义子接口继承父接口,并加上@FeignClient注解
package cn.edu.tju.service;
import org.springframework.cloud.openfeign.FeignClient;
@FeignClient(name = "myservice", url = "http://139.198.xxx.xxx:9301")
public interface SonInterface extends FatherInterface {
}
3.在控制器中注入子接口
package cn.edu.tju.controller;
import cn.edu.tju.service.SonInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class InheritanceController {
@Autowired
private SonInterface sonInterface;
@RequestMapping("/testInherit")
public String test(){
String result=sonInterface.getTime();
return result;
}
}