支持Java、C++、Python、Go等主流语言 1.3 典型应用场景 protobuf特别适合以下场景: 微服务间的通信数据格式 需要长期存储的结构化数据 网络通信协议 需要高性能序列化的场合 二、protobuf-java 依赖详解 2.1 依赖配置 在Maven项目中,添加protobuf-java依赖如下: <dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java</artifactId> <version>3.21.12</version> </dependency> 2.2 依赖组成 protobuf-java 中使用protobuf作为HTTP消息格式: 添加依赖: <dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java 通过本文的介绍,你应该已经掌握了: protobuf的基本概念和优势 如何在Java项目中集成protobuf-java 定义和编译.proto文件的方法 各种Java操作protobuf的技巧 实际应用场景和最佳实践
添加protobuf-java依赖 在Maven项目中添加protobuf-java依赖: <dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java</artifactId> <version>3.13.0</version> </dependency> 注:这里protobuf-java
groupId>commons-collections</groupId> </exclusion> <exclusion> <artifactId>protobuf-java </groupId> </exclusion> <exclusion> <artifactId>protobuf-java </groupId> </exclusion> <exclusion> <artifactId>protobuf-java > <dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java </groupId> </exclusion> <exclusion> <artifactId>protobuf-java
dependencies { //protobuf implementation "com.google.protobuf:protobuf-java:3.1.0" implementation ('com.squareup.retrofit2 :converter-protobuf:2.2.0') { exclude group: 'com.google.protobuf', module: 'protobuf-java'
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.2' 2.在app中的build.gradle添加两个protobuf依赖库:protobuf-java protobuf-java是用来处理java代码的,protoc是处理C或者C++代码的。 ? apply plugin: 'com.google.protobuf' implementation 'com.google.protobuf:protobuf-java:3.1.0' implementation
dependency> <dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java
Android 设备上使用而定制的 , 更适合移动端使用 ; dependencies { // You need to depend on the lite runtime library, not protobuf-java Protobuf 3.8 之后的版本 , 使用如下设置 : dependencies { // You need to depend on the lite runtime library, not protobuf-java
升降依赖版本解决 查看上面的冲突检测进行升降版本 Jar隔离 当然不是所有情况都可以通过升降级jar解决冲突,举个例子: 如上图假设应用系统同时依赖A.jar,B.jar,而A.jar,B.jar都依赖protobuf-java 包名替换(shade) 比如我这Mysql中依赖的版本 <dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java /version> </dependency> 其它依赖的版本 <dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java
Protobuf Runtime,针对特定语言的运行时库,如java中即是protobuf-java前缀的jar包。 protoc-gen-grpc-java插件,生成通讯代码,如: ? :github官网) 此com.google.protobuf:protoc:3.0.0-beta-2:exe:${os.detected.classifier}中的版本号3.0.0-beta-2要和protobuf-java
这一块就不去细讲版本了直接安装我的版本来就可以了展开代码语言:XMLAI代码解释<dependency><groupId>com.google.protobuf</groupId><artifactId>protobuf-java dubbo-serialization-api</artifactId><groupId>org.apache.dubbo</groupId></exclusion><exclusion><artifactId>protobuf-java
2.4 mysql-connector-java 2.5 shiro-spring 2.6 mybatis-plus 2.7 mybatisplus-spring-boot-starter 2.8 protobuf-java 2.8 protobuf-java Protobuf-java依赖是Google Protocol Buffers(简称Protobuf)的一个Java实现,它允许开发者使用一种与语言无关的格式来序列化结构化数据 在Java项目中,引入protobuf-java依赖可以方便地实现跨平台、跨语言的数据交换。
编译 --> <dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java
Maven Ubuntu TLS 22 Java Maven 准备工作 目录结构 pom.xml的配置 protoc 维护protoc的插件 指定读取的proto文件位置 指定生成路径 多操作系统支持 指定protobuf-java artifactId>os-maven-plugin</artifactId> <version>1.7.1</version> </extension> </extensions> 指定protobuf-java 这就需要引入包含这些底层代码的其他依赖,比如protobuf-java。这些依赖有版本号,也就意味着protoc也要与之适配。 <dependencies> <dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java dependencies> <dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java
dependencies> <dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java dependencies> <dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java
<dependency> 14 <groupId>com.google.protobuf</groupId> 15 <artifactId>protobuf-java protocCommand> 这里的protoc编译器的版本,必须与 <dependency> <groupId>com.google.protobuf</groupId> <artifactId>protobuf-java
-- https://mvnrepository.com/artifact/com.google.protobuf/protobuf-java --> <dependency> <groupId> com.google.protobuf</groupId> <artifactId>protobuf-java</artifactId> <version>3.5.1</version> <
artifactId> <version>2.1.0</version> <exclusions> <exclusion> <artifactId>protobuf-java
<dependency> 21 <groupId>com.google.protobuf</groupId> 22 <artifactId>protobuf-java <dependency> 14 <groupId>com.google.protobuf</groupId> 15 <artifactId>protobuf-java <dependency> 14 <groupId>com.google.protobuf</groupId> 15 <artifactId>protobuf-java
org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion") implementation("com.google.protobuf:protobuf-java
> d29vzk4ow07wi7.cloudfront.net > Could not download protobuf-java.jar (com.google.protobuf:protobuf-java :3.4.0) > Could not get resource 'https://jcenter.bintray.com/com/google/protobuf/protobuf-java