为什么我的协议没有生成 gprc 服务存根?

发布于 2025-01-09 14:44:01 字数 1899 浏览 1 评论 0原文

我正在将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一梦等七年七年为一梦 2025-01-16 14:44:01

我对此进行了尝试,并且能够生成 OrderService 存根类。这就是我所做的:

  1. start.spring.io 创建一个新的 Spring Boot 应用程序,
  2. 使用以下内容更新 pom.xml问题中的确切 XML 片段。
  3. 将 proto 定义添加到 src/main/proto/demo.proto
  4. 运行 ./mvnw clean install

我在 target/classes/com/aeonai/proto 下得到的是这些文件:

Demo$OrderRequest$1.class
Demo$OrderRequest$Builder.class
Demo$OrderRequest.class
Demo$OrderRequestOrBuilder.class
Demo$OrderResponse$1.class
Demo$OrderResponse$Builder.class
Demo$OrderResponse.class
Demo$OrderResponseOrBuilder.class
Demo.class
OrderServiceGrpc$1.class
OrderServiceGrpc$2.class
OrderServiceGrpc$3.class
OrderServiceGrpc$MethodHandlers.class
OrderServiceGrpc$OrderServiceBaseDescriptorSupplier.class
OrderServiceGrpc$OrderServiceBlockingStub.class
OrderServiceGrpc$OrderServiceFileDescriptorSupplier.class
OrderServiceGrpc$OrderServiceFutureStub.class
OrderServiceGrpc$OrderServiceImplBase.class
OrderServiceGrpc$OrderServiceMethodDescriptorSupplier.class
OrderServiceGrpc$OrderServiceStub.class
OrderServiceGrpc.class

OrderService 类在那里,但请注意,它们不是“Demo”类的内部类。在不知道您的确切项目设置的情况下,我不确定如何提供进一步的帮助,但您可以尝试我采取的步骤,看看是否可以获得服务类。如果您这样做,请查看实际项目设置的增量是多少。

I took a crack at this and I was able to generate the OrderService stub classes. Here's what I did:

  1. Create a fresh Spring Boot app at start.spring.io
  2. Update pom.xml with the exact XML snippets from the question.
  3. Add the proto definition to src/main/proto/demo.proto
  4. Run ./mvnw clean install

What I get in under target/classes/com/aeonai/proto are these files:

Demo$OrderRequest$1.class
Demo$OrderRequest$Builder.class
Demo$OrderRequest.class
Demo$OrderRequestOrBuilder.class
Demo$OrderResponse$1.class
Demo$OrderResponse$Builder.class
Demo$OrderResponse.class
Demo$OrderResponseOrBuilder.class
Demo.class
OrderServiceGrpc$1.class
OrderServiceGrpc$2.class
OrderServiceGrpc$3.class
OrderServiceGrpc$MethodHandlers.class
OrderServiceGrpc$OrderServiceBaseDescriptorSupplier.class
OrderServiceGrpc$OrderServiceBlockingStub.class
OrderServiceGrpc$OrderServiceFileDescriptorSupplier.class
OrderServiceGrpc$OrderServiceFutureStub.class
OrderServiceGrpc$OrderServiceImplBase.class
OrderServiceGrpc$OrderServiceMethodDescriptorSupplier.class
OrderServiceGrpc$OrderServiceStub.class
OrderServiceGrpc.class

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文