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 不允许远程 ...
随机推荐
- pycharm git 提交使用情况
在IDEA中进行分支切换时,出现如此错误,导致无法正常切换: error: The following untracked working tree files would be overwritte ...
- python文件名不要跟模块名相同,报错AttributeError: 'module' object has no attribute 'Differ'
python中的文件都会生成pyc文件,包括模块也是这样,所以调用模块的时候,实际上会调用模块.pyc文件:在这个前提下,如果将文件名命名成跟模块名一样,在同一目录下就会生成一个跟模块名一样的pyc文 ...
- 【Html 学习笔记】第六节——列表
无序列表:<ul></ul> 有序列表:<ol start=$num></ol> 不同类型的无序列表:<ul type="***&quo ...
- python3 堆排序
思路: 1.建立堆 2.得到堆顶元素,为最大元素 3.去掉堆顶,将堆最后一个元素放到堆顶,此时可通过一次调整重新使堆有序. 4.堆顶元素为第二大元素. 5.重复步骤3,直到堆变空. 动画 代码: de ...
- ping命令知识 Ping命令工作原理详解
在网络应用中,ping网速与IP地址等都是非常常用的命令,但大家知道ping命令的工作原理吗?要知道这其中的奥秘,我们有必要来看看Ping命令的工作过程到底是怎么样的.下面介绍下ping命令的详细知识 ...
- @Transactional的readOnly、timeout
1.@Transactional的readOnly 在使用@Transactional注解的时候,有一个属性是readOnly,默认值是false readOnly的意思就是当前的方法是只读的,也就是 ...
- QT 相关书籍
qt qucik 核心编程 个人觉得此书写得非常之好....这位作者的另外一本虽然没看过,估计也不错 https://bbs.csdn.net/topics/390942701?list=lz qt5 ...
- 迭代器、foreach循环、泛型集合
集合的迭代 语法:Iterator<Object> it=集合.iterator(); while(it.hasNext()){ Object obj=it.next(); } is.ha ...
- http和https区别
超文本传输协议 HTTP 协议被用于在 Web 浏览器和网站服务器之间传递信息,HTTP 协议以明文方式发送内容,不提供任何方式的数据加密,如果攻击者截取了 Web 浏览器和网站服务器之间的传输报文, ...
- Shell 命令行实现将一个站点页面全部下载到本地并替换其中链接的脚本
Shell 命令行实现将一个站点页面全部下载到本地并替换其中链接的脚本 不知道为什么,我总想用 Shell 脚本来实现把一个站点内容给下载下来.但是下载什么站点我确不知道.今天尝试了一下利用 curl ...