feign 序列化_Spring Feign 序列化机制

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

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

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。


版权声明:本文为weixin_39777242原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。