1.公式文書
HTTPS:// cloud.spring.io/spring-cloud-static/spring-cloud-openfeign/2.2.2.RELEASE/reference/html/
2. [追加の依存
< 依存性> < のgroupId > org.springframework.boot </ のgroupId > < たartifactId >ばねブートスタータウェブ</ たartifactId > </ 依存> < 依存性> < のgroupId > org.springframework.cloud </ のgroupId > < たartifactId >春・クラウド・スターター・ネットフリックス-ユーレカ・クライアント</ たartifactId > </ 依存関係> < 依存> <groupId> org.springframework.cloud </ のgroupId > < たartifactId >ばねクラウドスタータopenfeign </ たartifactId > </ 依存>
起動クラスのノートを追加3。
輸入org.mybatis.spring.annotation.MapperScan; 輸入org.springframework.boot.SpringApplication。 輸入org.springframework.boot.autoconfigure.SpringBootApplication。 輸入org.springframework.cloud.openfeign.EnableFeignClients。 @SpringBootApplication // @MapperScan( "cn.ytheng.order_service") @EnableFeignClients パブリック クラスOrderServiceApplication { 公共 静的 ボイドメイン(文字列[]引数){ SpringApplication.run(OrderServiceApplication。クラス、引数)。 } }
4. [追加装うインタフェース
インポートorg.springframework.cloud.openfeign.FeignClient; インポートorg.springframework.web.bind.annotation.GetMapping; インポートorg.springframework.web.bind.annotation.RequestParam; / ** * *製品サービスクライアント *製品サービス:コールサービス名、そのspring.application.name * * / @FeignClient(名 = "製品・サービス" ) のパブリック インターフェイスProductClient { (@GetMapping "/ API / V1 /製品/検索"を) 文字列getById(@RequestParam( " ID「)のint ID); }
5. [追加コントローラ
輸入cn.theng.order_service.service.ProductClient; 輸入org.springframework.beans.factory.annotation.Autowired; 輸入org.springframework.web.bind.annotation.PostMapping。 輸入org.springframework.web.bind.annotation.RequestMapping。 輸入org.springframework.web.bind.annotation.RequestParam; 輸入org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping( "/ API / V1 /注文" ) パブリック クラスProductOrderController { @Autowired プライベートProductClient productClient。 @PostMapping( "/ TEST2" ) パブリックオブジェクトTEST2(@RequestParam( "PRODUCT_ID")INT PRODUCTID){ 文字列の生成物 = productClient.getById(商品コード)。 戻る「成功」。 } }
application.yml設定を追加6
サーバー: ポート: 8781 ユーレカ: クライアント: serviceURLの: defaultZoneます。http:// localhostを:8761 /ユーレカ/ 春: アプリケーション: 名前:注文 -service
7.アクセス住所