做局部性的自定义configuration

feign提供给我们的可配置的东西

这是决定我们为什么之前可以使用SpringMVC来服务调用的原因。因为feign默认提供给我们的就是SpringMvcContract.
这里我们来演示如果我们不用SpringMvc的Contract那么具体怎么去操作?

configuration不能在Application的作用域之内,如果在作用域内它默认就会把它加载进来,会出问题。

@SpringBootApplication 默认扫描的就是同级别和子目录

我们consumer同级别建一个包feignconf

application管的就是consumer包下的以及它的子包

我们在feignconf下加载的就是我们额外的配置。

我们去改变contract,选择feign包下的

使用feign默认提供给我们的集成方式,

上面加个@Bean注解

启动eurekaServer、provider和consumer服务
访问consumer的接口地址

重启consumer服务就报错了:

Caused by: java.lang.IllegalStateException: Method ProviderApi#providerPost(String,String,UserModel) not annotated with HTTP method type (ex. GET, POST)

默认的配置不能识别我们当前写的语法

feign的写法演示


演示下feign默认提供的方式。这是feign的写法,写法非常的奇怪。

把原来的两个方法,invokerProviderController和providerPost都注释掉。

@RequestLine("GET /sayhello?message={message}")
String invokerProviderController(@Param("message") String message);

 




ProviderAPIImpl类里,这里也注释掉

重启服务,也可以正常的访问。这是用feign自己的注解访问的方式。

http://localhost:7201/sayhello/feign?message=imooc

总结


这里我们演示了默认的和SpringMvc的Contract

进入Default方法

这里就是Contract里面有个Default

以上就是自定义配置给大家讲的内容

结束

 

相关文章:

  • 2021-05-29
  • 2021-07-04
  • 2021-06-02
  • 2021-07-14
  • 2021-10-06
  • 2022-01-25
  • 2022-02-14
猜你喜欢
  • 2021-11-22
  • 2022-12-23
  • 2021-09-30
  • 2021-08-23
  • 2022-12-23
  • 2022-01-05
  • 2021-12-20
相关资源
相似解决方案