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