为什么我的协议没有生成 gprc 服务存根?
我正在将 grpc 拉入我的 spring-boot-project 中。我引入了这个依赖项:
<dependency>
<groupId>io.github.lognet</groupId>
<artifactId>grpc-spring-boot-starter</artifactId>
<version>4.5.8</version>
</dependency>
这是我的 plugins
部分:
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.6.2</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.17.2:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.39.0:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
这是我的协议文件:
syntax = "proto3";
option java_package = "com.aeonai.proto";
service OrderService {
rpc ExecuteOrder(OrderRequest) returns (OrderResponse) {};
}
message OrderRequest {
string email = 1;
string product = 2;
int32 amount = 3;
}
message OrderResponse {
string info = 1;
}
当我运行 mvn clean install
时,我得到了除 OrderService 之外的所有 java 类。创建服务还需要做什么?
I am pulling grpc into my spring-boot-project. I pulled in this dependency:
<dependency>
<groupId>io.github.lognet</groupId>
<artifactId>grpc-spring-boot-starter</artifactId>
<version>4.5.8</version>
</dependency>
Here is my plugins
section:
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.6.2</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.17.2:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.39.0:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Here is my protoc file:
syntax = "proto3";
option java_package = "com.aeonai.proto";
service OrderService {
rpc ExecuteOrder(OrderRequest) returns (OrderResponse) {};
}
message OrderRequest {
string email = 1;
string product = 2;
int32 amount = 3;
}
message OrderResponse {
string info = 1;
}
When I run mvn clean install
I get all of the java classes, other than the OrderService. What else needs to happen to create the service?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对此进行了尝试,并且能够生成 OrderService 存根类。这就是我所做的:
我在 target/classes/com/aeonai/proto 下得到的是这些文件:
OrderService 类在那里,但请注意,它们不是“Demo”类的内部类。在不知道您的确切项目设置的情况下,我不确定如何提供进一步的帮助,但您可以尝试我采取的步骤,看看是否可以获得服务类。如果您这样做,请查看实际项目设置的增量是多少。
I took a crack at this and I was able to generate the OrderService stub classes. Here's what I did:
What I get in under target/classes/com/aeonai/proto are these files:
The OrderService classes are there, but note that they are not inner classes of the "Demo" class. Without knowing your exact project setup I'm not sure how to help further, but you could try the steps I took and see if you then get the service classes. And if you do, see what the delta is with your actual project setup.