protobuf新增message报错:类型已存在
问题现象:在一个已有的proto文件(RecommendResponse.proto)中新增一个message(BookList),用maven编译proto文件时报错:
E:\workspace\ms-selection-service\ms-selection-api>mvn clean install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Detecting the operating system and CPU architecture
[INFO] ------------------------------------------------------------------------
[INFO] os.detected.name: windows
[INFO] os.detected.arch: x86_64
[INFO] os.detected.version: 10.0
[INFO] os.detected.version.major:
[INFO] os.detected.version.minor:
[INFO] os.detected.classifier: windows-x86_64
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building ms-selection-api 1.0.
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ ms-selection-api ---
[INFO] Deleting E:\workspace\ms-selection-service\ms-selection-api\target
[INFO]
[INFO] --- protobuf-maven-plugin:0.5.:compile (default) @ ms-selection-api ---
[INFO] Compiling proto file(s) to E:\workspace\ms-selection-service\ms-selection-api\target\generated-sources\protobuf\java
[ERROR] PROTOC FAILED: recommend/RecommendResponse.proto::: "BookList.bookName" is already defined in file "contentrecommend/ContentRecommendResponse.proto".
recommend/RecommendResponse.proto::: "BookList.authorName" is already defined in file "contentrecommend/ContentRecommendResponse.proto".
recommend/RecommendResponse.proto::: "BookList.bookCover" is already defined in file "contentrecommend/ContentRecommendResponse.proto".
recommend/RecommendResponse.proto::: "BookList.bookUrl" is already defined in file "contentrecommend/ContentRecommendResponse.proto".
recommend/RecommendResponse.proto::: "BookList.coPercent" is already defined in file "contentrecommend/ContentRecommendResponse.proto".
recommend/RecommendResponse.proto::: "BookList.contentType" is already defined in file "contentrecommend/ContentRecommendResponse.proto".
recommend/RecommendResponse.proto::: "BookList" is already defined in file "contentrecommend/ContentRecommendResponse.proto".
recommend/RecommendResponse.proto::: "BookList" seems to be defined in "contentrecommend/ContentRecommendResponse.proto", which is not imported by "recommend/RecommendResponse.proto". To use it here, please add the necessary import.
先看下RecommendResponse.proto:
syntax = "proto3"; option java_package = "cn.wlf.selection.proto.base"; message RecommendResponse { string pluginCode=;
string status=;
string isvisable=;
string isShowLine=;
Recommend data=;
string messageDesc=;
repeated BookList bookList= ; } message Recommend{ repeated RecommendData buttons=;
map<string, string> ctag = ;
string isMarginTop=;
string isMarginBottom=; } message RecommendData{ string name=; string url=;
} message BookList{
string bookName=;
string authorName=;
string bookCover=;
string bookUrl=;
string coPercent=;
string contentType=; }
再看ContentRecommendResponse.proto:
syntax = "proto3"; option java_package = "cn.wlf.selection.proto.base"; message ContentRecommendResponse {
string pluginCode=; string status=; string isvisable=; string messageDesc=; ContentRecommendData data=; }
message ContentRecommendData{ string isMarginTop = ; string isMarginBottom = ; string isPaddingTop = ; string isShowLine = ; string dataFrom = ; string title = ; string style = ; repeated BookList bookList=; BiData biData = ; }
message BookList{
string bookName=;
string authorName=;
string bookCover=;
string bookUrl=;
string coPercent=;
string contentType=;
} message BiData{ string msisdn = ;
string bid = ;
string pageNo = ;
string showNum = ;
string clientVersion = ;
string instanceId = ;
}
问题定位:从报错信息中其实已经告诉我们,在ContentRecommendResponse.proto已经存在BookList这个message了,从上面也能看到两个proto存在同名message。
问题解决:
1、如果新增的BookList跟已有的数据结构一样,那么只需要引入即可,RecommendResponse.proto改为:
syntax = "proto3"; option java_package = "cn.wlf.selection.proto.base";
import "contentrecommend/ContentRecommendResponse.proto"; message RecommendResponse { string pluginCode=;
string status=;
string isvisable=;
string isShowLine=;
Recommend data=;
string messageDesc=;
repeated BookList bookList= ; } message Recommend{ repeated RecommendData buttons=;
map<string, string> ctag = ;
string isMarginTop=;
string isMarginBottom=; } message RecommendData{ string name=; string url=;
}
2、如果BookList数据结构改了,那么就没法复用了,只能改类名,RecommendResponse.proto改为:
syntax = "proto3"; option java_package = "cn.wlf.selection.proto.base"; message RecommendResponse { string pluginCode=;
string status=;
string isvisable=;
string isShowLine=;
Recommend data=;
string messageDesc=;
repeated BookListNew bookList= ; } message Recommend{ repeated RecommendData buttons=;
map<string, string> ctag = ;
string isMarginTop=;
string isMarginBottom=; } message RecommendData{ string name=; string url=;
} message BookListNew{
string bookCover=;
}
虽然类名从BookList改为BookListNew,但实例名没改,还是bookList,最终输出的响应字段名还是叫bookList的。
以上两种情况修改后跑maven均可成功编译出java文件。
protobuf新增message报错:类型已存在的更多相关文章
- 报错:已有打开的与此命令相关联的 DataReader,必须首先将它关闭。
SqlParameter[] sp = { new SqlParameter("@nGridID",SqlDbType.BigInt), new SqlParameter(&quo ...
- asp.net使用post方式action到另一个页面,在另一个页面接受form表单的值!(报错,已解决!)
原文:asp.net使用post方式action到另一个页面,在另一个页面接受form表单的值!(报错,已解决!) 我想用post的方式把一个页面表单的值,传到另一个页面.当我点击Default.as ...
- SQL 关联外键报错类型不匹配
如题,关联外键的时候,报错类型匹配.但是两个 类型都是int sql 如下: CREATE TABLE IF NOT EXISTS `alert_receiver_map` ( `id` INT UN ...
- 使用自编译的Emacs26.0.50build10版本,helm报错(已解决)
使用自编译的Emacs26.0.50build10版本,helm报错(已解决) */--> code {color: #FF0000} pre.src {background-color: #0 ...
- Core在IIS的热发布问题或者报错文件已在另一个程序中打开
关于Core发布到IIS的热发布问题,或者覆盖dll文件的时候会报错"文件已在另一个程序中打开",也就是无法覆盖程序的问题,经过百度和分析总结以下几种方案: 一.使用app_off ...
- console报错类型
常见 console报错 Error 错误 EvalError 全局错误 RangeError 引用(范围)错误 ReferenceError 参数(参考)错误 SyntaxError 语法错误 ty ...
- Flink解析kafka canal未压平数据为message报错
canal使用非flatmessage方式获取mysql bin log日志发至kafka比直接发送json效率要高很多,数据发到kafka后需要实时解析为json,这里可以使用strom或者flin ...
- 机器装多个版本php,并安装redis插件报错【已解决】
机器原版本php5.5.3 适应新的框架安装了7.1.12 期间遇到的小问题就是安装 redis插件的时候,总报错,报错如下: Starting php-fpm [02-Jan-2019 10:15: ...
- SQL Server 2008 报错:已成功与服务器建立连接,但是在登录前的握手期间发生错误
今天SqlServer 2008连接数据库时报错:已成功与服务器建立连接,但是在登录前的握手期间发生错误.在连接到 SQL Server 2008 时,在默认的设置下 SQL Server 不允许远程 ...
随机推荐
- Linux 挂载系统盘
适用系统:非IO优化+SSD云盘Linux(Redhat , CentOS,Debian,Ubuntu)实例,IO优化实例+SSD云盘数据盘分区挂载建议使用脚本:工具:auto_fdisk_ssd.s ...
- vue的slot的使用问题
slot的使用问题 根据官方文档来说,有三种使用方式 https://cn.vuejs.org/v2/guide/components.html#%E4%BD%BF%E7%94%A8%E6%8F%92 ...
- iOS自动化探索(九)使用Jenkins自动化打包并发布iOS App
继前一篇: Mac环境下安装Jenkins Jenkins安装好后, 我们试着创建一个iOS自动打包并发布的任务 iOS App构建必须在MAC上面使用xcode进行,所以我们要安装下xcode集成插 ...
- SSM整合AOP,日志框架和拦截器
前言 日志是所有系统必不可少的部分,而AOP在MVC通常用于监控方法调用,可以生成一个traceid,记录从用户调用到底层数据库的数据链路,帮助监控和排查问题. AOP 现在做一个简单的前置切面,用来 ...
- 优化JDBC封装
可重用性较强的JDBC封装 以下为代码,注释中写了主要思想 主类 com.util.JDBCUtil.java package com.util; import java.lang.reflect.F ...
- PHP错误Parse error: syntax error, unexpected end of file in test.php on line 12解决方法
出现这个错误的原因就是语法错误,肯定是PHP程序的书写不规范造成,PHP语句标识符错了,没有在php.ini中开启短标签!八成是这个原因,啊啊啊! 今天在写PHP程序的时候总是出现这样的错误:Pars ...
- C# 超级狗 二次开发 读写数据 激活验证 存储数据库连接字符串
本文主要讲解如果使用C#语言来对超级狗进行二次开发,如果仅仅是做个激活的功能,可以参照另一篇博客,地址:http://www.cnblogs.com/dathlin/p/8487842.html 如果 ...
- vuex(三)actions
actions:既然mutations只能处理同步函数,我大js全靠‘异步回调’吃饭,怎么能没有异步,于是actions出现了... actions和mutations的区别 1.Acti ...
- 【剑指offer-21】调整数组顺序使奇数位于偶数前面,C++实现(冒泡排序)
1.题目 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于位于数组的后半部分. 2.思路 本题有两种解法,一种是不保证数组稳定性的解法,一种是保 ...
- CentOS下glibc更新
使用java -agentpath=xxx时报该错,提示glibc版本过低:version `GLIBC_2.14' not found (required by /data/jjns/UEISecu ...