springcloud 서비스 소비자-Feign
3556 단어 스프링
Feign 은 Http 클 라 이언 트 를 더 간단하게 만 드 는 성명 식 가짜 Http 클 라 이언 트 입 니 다.Feign 을 사용 하려 면 하나의 인 터 페 이 스 를 만 들 고 주석 을 추가 하면 Feign 주석 과 JAX-RS 주석 을 사용 할 수 있 습 니 다.Feign 은 기본적으로 리본 을 통합 하고 유레카 와 결합 했다.
실천 하 다.
1.eureka-server 를 시작 하고 포트 는 8761 입 니 다.service-hi 를 두 번 시작 하고 포트 는 각각 8762,8763 입 니 다.
2.feign 서 비 스 를 만 듭 니 다.
(1)새로운 spring-boot 프로젝트 를 만 듭 니 다.service-fegn 이 라 고 이름 을 지 었 습 니 다.pom 파일 에 Feign 을 도입 하 는 시작 은 spring-cloud-starter-feign 에 의존 합 니 다.eureka 의 시작 은 spring-cloud-starter-netflix-eureka-client 에 의존 합 니 다.웹 의 시작 은 spring-boot-starter-web 에 의존 합 니 다.
4.0.0
com.forezp
service-feign
0.0.1-SNAPSHOT
jar
service-feign
Demo project for Spring Boot
com.forezp
sc-f-chapter3
0.0.1-SNAPSHOT
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
org.springframework.boot
spring-boot-starter-web
org.springframework.cloud
spring-cloud-starter-openfeign
(2) application.yml , service-feign, 8765, http://localhost:8761/eureka/
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
server:
port: 8765
spring:
application:
name: service-feign
(3) ServiceFeignApplication, @EnableFeignClient Feign 。
@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
@EnableFeignClients
public class ServiceFeignApplication {
public static void main(String[] args) {
SpringApplication.run( ServiceFeignApplication.class, args );
}
}
(4) feign , @FeignClient(" ") 。
@FeignClient(value = "service-hi")
public interface SchedualServiceHi {
@RequestMapping(value = "/hi",method = RequestMethod.GET)
String sayHiFromClientOne(@RequestParam(value = "name") String name);
}
(5) Web controller , “/hi” API , Feign SchedualServiceHi 。
@RestController
public class HiController {
// , 。 Bean , , 。
@Autowired
SchedualServiceHi schedualServiceHi;
@GetMapping(value = "/hi")
public String sayHi(@RequestParam String name) {
return schedualServiceHi.sayHiFromClientOne( name );
}
}
, http://localhost:8765/hi?name=xxx
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
스프링 MVC 1편 - 백엔드 웹 개발 핵심 기술 [ MVC 프레임워크 만들기 ]프론트 컨트롤러 도입 - v1 프론트 컨트롤러 도입 - v1 프론트 컨트롤러는 이 인터페이스를 호출해서 구현과 관계없이 로직의 일관성을 가져갈 수 있다. FrontControllerServletV1 - 프론트 컨트롤...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.