Spring Feign 序列化机制


Spring Cloud封装Feign,直接使用Spring MVC注解以及HttpMessageConverters来序列化。

 

Spring Boot有autoconfigure机制,当spring boot中引入了spring-web jar包的时候,HttpMessageConvertersAutoConfiguration便会起作用,另外当引入了ObjectMapper类时候,MappingJackson2HttpMessageConverterConfiguration便会起作用,从而自动加入了HttpMessageConverters中,这样feign就会直接来序列化json了。

 

Declarative REST Client: Feign中有这么一段话

 

FooConfiguration does not need to be annotated with @Configuration. However, if it is, then take care to exclude it from any @ComponentScan that would otherwise include this configuration as it will become the default source for feign.Decoder, feign.Encoder, feign.Contract, etc., when specified. This can be avoided by putting it in a separate, non-overlapping package from any @ComponentScan or @SpringBootApplication, or it can be explicitly excluded in @ComponentScan.

大致意思是,FeignClient注解上可以指定configuration属性,但是对于指定的configuration属性的类不需要使用@Configuration注解,不然这个里面设置的属性将会覆盖默认的配置属性,转而使用该configuration配置的。如果不使用@Configuration注解,那么只有该FeignClient会使用该configuration。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM