多语言展示
当前在线:1024今日阅读:195今日分享:41

springboot2中整合protobuf错误

springboot2中需要支持protobuf对象进行序列化,反序列化,整合时出现错误406,不支持类型
工具/原料
1

springboot2

2

protobuf

方法/步骤
1

如果继承WebMvcConfigurationSupport这类时需要重写configureMessageConverters(),再此方法中,添加converters.add(new ProtobufHttpMessageConverter());

2

或者使用自定义代码:@Bean public ProtobufHttpMessageConverter protobufHttpMessageConverter(){     return new ProtobufHttpMessageConverter(); }

3

两种方法选其一,如果继承WebMvcConfigurationSupport类,必须重写configureMessageConverters(),否则使用第二种时不生效,protobufHttpMessageConverter不能加入到HttpMessageConverters中,导致解析protobuf对象时,不能正确处理。

注意事项

两个方法只能选其一

推荐信息