You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署Spring Cloud Function至GCP Functions时GcfJarLauncher类缺失

部署Spring Cloud Function到Google Cloud Functions时找不到GcfJarLauncher类的问题

我正尝试将一个简单的REST API部署到Google Cloud Functions。根据官方文档要求,函数目标必须设置为org.springframework.cloud.function.adapter.gcp.GcfJarLauncher,但执行部署命令后出现以下错误:

ERROR: (gcloud.alpha.functions.deploy) OperationError: code=3, message=Build failed: 
build succeeded but did not produce the class "org.springframework.cloud.function.adapter.gcp.GcfJarLauncher" 
specified as the function target: Error: class not found: org.springframework.cloud.function.adapter.gcp.GcfJarLauncher; 
Error ID: d818fd83

我在Cloud CLI中执行的部署命令为:

gcloud alpha functions deploy function-sample-gcp-http --entry-point org.springframework.cloud.function.adapter.gcp.GcfJarLauncher --runtime java11 --trigger-http --source target/deploy --memory 512MB

关键代码片段

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.divr-fx-test</groupId>
    <artifactId>divr-function</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>divr-function</name>
    <description>Function testing for DIVR</description>
    <properties>
        <java.version>11</java.version>
        <spring-cloud-function.version>4.0.0-SNAPSHOT</spring-cloud-function.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-function-web</artifactId>
            <version>3.2.8</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-function-web</artifactId>
            <version>3.2.8</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-function-dependencies</artifactId>
            <version>3.2.8</version>
            <type>pom</type>
        </dependency>
        <dependency>
          <groupId>com.google.cloud.functions</groupId>
          <artifactId>functions-framework-api</artifactId>
          <version>1.0.4</version>
          <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-function-adapter-gcp</artifactId>
            <version>3.2.8</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
              <!-- Build an executable JAR -->
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-jar-plugin</artifactId>
              <configuration>
                <archive>
                  <manifest>
                    <addClasspath>true</addClasspath>
                    <classpathPrefix>lib/</classpathPrefix>
                    <mainClass>com.mypackage.MyClass</mainClass>
                  </manifest>
                </archive>
              </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <outputDirectory>target/deploy</outputDirectory>
                </configuration>
                </plugin>
            <plugin>
                <groupId>com.google.cloud.functions</groupId>
                <artifactId>function-maven-plugin</artifactId>
                <version>0.9.1</version>
                <configuration>
<functionTarget>org.springframework.cloud.function.adapter.gcp.GcfJarLauncher</functionTarget>
                    <port>8080</port>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

主类代码

package com.fkgcp;

import java.util.function.Function;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class DivrFunctionApplication {

    public static void main(String[] args) {
        SpringApplication.run(DivrFunctionApplication.class, args);
    }

    
    // 这部分并非我所需,但所有教程都包含,故添加以测试是否会触发它而非我的REST函数
    @Bean 
    public Function<String, String> uppercase() {
        return value -> value.toUpperCase();
    }
}

MANIFEST.MF文件

文件位置:divr-function/src/main/resources/META-INF/MANIFEST.MF

内容:

Main-Class: com.fkgcp.DivrFunctionApplication

请问我遗漏了什么配置或步骤?

内容的提问来源于stack exchange,提问作者AylaWinters

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 06:30:52