当前位置:网站首页>Feignclient utilise un tutoriel détaillé (illustration)
Feignclient utilise un tutoriel détaillé (illustration)
2022-07-23 14:51:00 【Gérard pick - Shea】
@FeignClientUtilisez l'illustration détaillée du tutoriel
Action
@FeignClientUtilisé pour créer une déclaration estAPIInterface,L'interface estRESTfulStyle.FeignConçu pour être branché,Peut être injecté dans d'autres composants etFeignÀ utiliser ensemble.Le plus typique est siRibbonDisponible,FeignEtRibbonCombinaison de l'équilibrage de la charge.
@FeignClientPropriétés communes des étiquettes
- Capture d'écran du code source

name(EtvalueMême chose.):DésignationFeignClientNom de,Si le projet utiliseRibbon,nameLa propriété sera utilisée comme microservice(Le nom d'un centre)Nom de,Pour la découverte de services(L'illustration est la suivante:)- url: urlGénéralement utilisé pour la mise en service,Peut être spécifié [email protected]'adresse de l'appel(L'illustration est la suivante:)
- decode404()C'est - à - dire:404C'est décodé,Ou lancer une exception.
- configuration()PréciserFeignClientClasse de configuration pour,La classe de configuration par défaut estFeignClientsConfigurationCatégorie,Par défaut,Cette classe injecte par défautDecoder、EncoderEtConstantAttendez la configurationbean.
- fallback()Classe de traitement pour la configuration des fusibles.


- FeignClientClasse de configuration pour(configuration())
public class FeignUserSupportConfig
{
@Bean
@Primary
@Scope("prototype")
public Encoder multipartFormEncoder() {
return new SpringFormEncoder(new SpringEncoder(new ObjectFactory<HttpMessageConverters>() {
@Override
public HttpMessageConverters getObject() throws BeansException
{
return new HttpMessageConverters(new RestTemplate().getMessageConverters());
}
}));
}
@Bean
public feign.Logger.Level multipartLoggerLevel() {
return feign.Logger.Level.FULL;
}
}
Utiliser le processus
- 1. Augmentation de la classe de démarrage
@EnableFeignClients
- 2.Définir l'interface
package com.xxx.xxx.client;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Map;
@Component
/** * value = "user" Moyenne user Pour Appelez user ServicesId * spring.application.name=user */
@FeignClient(value = "user", configuration = UserSupportConfig.class)
public interface TestClientService {
/** * @param id * @return /user/selectById Pour userController Dans /user/selectById Adresse de la méthode */
@RequestMapping(value = "/user/selectById", method = RequestMethod.GET, produces = {
MediaType.APPLICATION_JSON_UTF8_VALUE}, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
/** * userId Pour les paramètres Il faut é[email protected] Sinon, une erreur est signalée. */
Map upload(@RequestParam("userId") Integer id);
}
- 3. Définir la classe de fusible ,Rappel en cas d'erreur:
import java.util.List;
import org.springframework.stereotype.Component;
@Component
public class Hysitx implements TestClientService {
@Override
public List<String> test(String[] names) {
System.out.println("L'appel d'interface a échoué");
return null;
}
}
- 4.Appelez
Et de baseserviceAppel cohérent
1.Introduction en premier @Autowired
2. Appelé directement dans la méthode
L'explication populaire peut le considérer comme unspring Bean Peut être considéré comme unService
Voilà[email protected] AjouterHeaderInformation
@FeignClient(name="custorm",fallback=Hysitx.class)
public interface IRemoteCallService {
@RequestMapping(value="/user/selectById",method = RequestMethod.POST,
headers = {
"Content-Type=application/json;charset=UTF-8"})
Map test(@RequestParam("userId") int id);
}
2. Ajouter avant les paramètres de la méthode @RequestHeaderNotes:
@FeignClient(name="custorm",fallback=Hysitx.class)
public interface IRemoteCallService {
@RequestMapping(value="/user/selectById",method = RequestMethod.POST,
headers = {
"Content-Type=application/json;charset=UTF-8"})
List<String> test(@RequestParam("userId")@RequestHeader("Authorization") int id);
}
@FeignClient(name="custorm",fallback=Hysitx.class)
public interface IRemoteCallService {
@RequestMapping(value="/user/selectById",method = RequestMethod.POST)
@Headers({
"Content-Type: application/json;charset=UTF-8"})
List<String> test(@RequestParam("userId") int id);
}
边栏推荐
- Regular expression common syntax parsing
- What is per title encoding?
- [WinForm] desktop program implementation scheme for screenshot recognition and calculation
- It is suggested that Siyuan notes can be compatible with third-party sync disks
- The win11 installation system prompts that VirtualBox is incompatible and needs to uninstall the solution of virtual, but the uninstall list cannot find the solution of virtual
- 云呐|公司固定资产如何管理?公司固定资产如何管理比较好?
- Dynamic programming -- knapsack problem
- 【无标题】
- Question 142 of Li Kou: circular linked list 2
- Using shell script to block IP with high scanning frequency
猜你喜欢

win11安装系统提示virtualBox不兼容需要卸载virtual的解决办法,但是卸载列表找不到virtual的解决办法
![[applet automation minium] i. framework introduction and environment construction](/img/1f/95b78e6574c3af3ff7abcf5db838f5.png)
[applet automation minium] i. framework introduction and environment construction

R语言实战应用案例:绘图篇(三)-多种组合图型绘制

工作小记:一次抓包

Authing 支持 Zadig 啦!云原生用户统一认证快速对接

Dynamic programming -- knapsack problem

Using shell script to block IP with high scanning frequency

Question 142 of Li Kou: circular linked list 2
![[can I do your first project?] Detailed introduction and Simulation Implementation of gzip](/img/92/dfef5887e2313f8025baf11c8f4379.png)
[can I do your first project?] Detailed introduction and Simulation Implementation of gzip

Cmake notes
随机推荐
Design and implementation of websocket universal packaging
CSDN writing method (II)
Towhee weekly model
Sword finger offer 46. translate numbers into strings
Jetpack系列之Room中存Map结构
Using shell script to block IP with high scanning frequency
Typora图床配置详细教程
Wacom firmware update error 123, digital board driver cannot be updated
Qt|模仿文字浮动字母
[software test] MQ abnormal test encountered in disk-to-disk work
直播课堂系统03-model类及实体
工作小记:一次抓包
Right click to create a new TXT. The new text file is missing. You can solve it by adding a registry. Find the ultimate solution that can't be solved
Towhee weekly model
可以进行2D或3D三角剖分的一些库
【小程序自动化Minium】三、元素定位- WXSS 选择器的使用
Advanced operation and maintenance 02
Using JS to parse and execute XSS automatically
【数组&&字符串&&宏练习题】
云呐|公司固定资产如何管理?公司固定资产如何管理比较好?