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 不允许远程 ...
随机推荐
- python3.6环境部署文档
python3.6环境部署文档 内容 Linux部署Python3.6环境 Mac部署Python3.6环境 Window10部署Python3.6环境 Pycharm安装 1. Linux部署P ...
- 前端开发必备 - Emmet
介绍 Emmet (前身为 Zen Coding) 是一个能大幅度提高前端开发效率的一个工具. 基本上,大多数的文本编辑器都会允许你存储和重用一些代码块,我们称之为"片段".虽然片 ...
- PHP for循环的写法和示例
For循环是最近的循环语句之一,无论哪种语言,都有这个循环语句,也是我们工作中常用的循环方法. 语法规则: for (expr1; expr2; expr3){ 要执行的代码 } expr1:表示循环 ...
- C++STL内存配置的设计思想与关键源码分析
说明:我认为要读懂STL中allocator部分的源码,并汲取它的思想,至少以下几点知识你要了解:operator new和operator delete.handler函数以及一点模板知识.否则,下 ...
- jmeter测试FTP
1.下载并运行FTP服务器软件:Quick Easy FTP Server V4.0.0.exe 2.点击右上角的绿色按钮,开启服务器,直到中间的红色按钮亮起 3.在账户管理处可以管理账号信息(用户名 ...
- 链表实现队列C语言写法
#include<iostream> #include<cstdio> #include<cstdlib> using namespace std; typedef ...
- charles抓包--手机端
Fiddler和charles都是抓包工具,可以抓到pc端的请求,手机上设置代理后也可以抓到手机上的请求,也可以修改请求数据和返回的数据. 在接口已经使用的时候,比如说已经用到了app上,app端测试 ...
- [Linux] 终端设置只显示当前目录及终端美化
1.只显示当前目录 vim ~/.bashrc 找到位置: if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($d ...
- ZooKeeper 学习资料积累
跟着实例学习ZooKeeper的用法: 临时节点 跟着实例学习ZooKeeper的用法: 缓存 跟着实例学习ZooKeeper的用法: 队列 跟着实例学习ZooKeeper的用法: Barrier 跟 ...
- hexo部署Github博客
例子:https://aquarius1993.github.io/blog/ 仓库:https://github.com/Aquarius1993/blog (前提是已经安装Xcode和git) 1 ...