1

When i deploy my jar file in GCP cloud-functions, i am getting the below exception

2021-03-11T17:30:04.835Zarun-function-http Exception in thread "main" java.lang.RuntimeException: Class com.arun.serverless.CloudFunctionMain does not implement com.google.cloud.functions.HttpFunction at com.google.cloud.functions.invoker.HttpFunctionExecutor.forClass(HttpFunctionExecutor.java:47) at com.google.cloud.functions.invoker.runner.Invoker.startServer(Invoker.java:252) at com.google.cloud.functions.invoker.runner.Invoker.main(Invoker.java:127)
Exception in thread "main" java.lang.RuntimeException: Class com.arun.serverless.CloudFunctionMain does not implement com.google.cloud.functions.HttpFunction at com.google.cloud.functions.invoker.HttpFunctionExecutor.forClass(HttpFunctionExecutor.java:47) at com.google.cloud.functions.invoker.runner.Invoker.startServer(Invoker.java:252) at com.google.cloud.functions.invoker.runner.Invoker.main(Invoker.java:127)

This is another error that i get in CLI

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

This is my source code

This is my spring main class

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class CloudFunctionMain {

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

}

This is my function

import java.util.function.Function;

public class ReverseString implements Function<String, String> {

    @Override
    public String apply(String actualString) {
        return "The reversed string is " + new StringBuilder(actualString).reverse().toString();
    }
}

This is what my build.gradle contains

plugins {
    id 'java'
}

group 'com.arun'
//version '1.0'

repositories {
    mavenRepository()
}

dependencies {
    implementation 'org.springframework.cloud:spring-cloud-function-adapter-gcp:3.1.1'
    implementation 'org.springframework.cloud:spring-cloud-starter-function-web:3.1.1'
}

It works perfectly fine in my local... But when i deploy in GCP Cloud functions, it isn't getting started and stopping with the exception that i pasted above

Arun
  • 3,440
  • 11
  • 60
  • 108
  • This seems like a missing feature. Please raise an issue - https://github.com/spring-cloud/spring-cloud-function and we'l work withe the google team to address it – Oleg Zhurakousky Mar 12 '21 at 13:28
  • thanks. I raised an issue https://github.com/spring-cloud/spring-cloud-function/issues/665 – Arun Mar 12 '21 at 13:41
  • Hello. Class com.arun.serverless.CloudFunctionMain does not implement com.google.cloud.functions.HttpFunction states a clear indication of what the issue may be. An interface is not implemented. @Oleg Can you please add why this is a missing feature? – MrTech Mar 15 '21 at 14:53
  • I dont think spring-cloud needs to implement `HttpFunction` interface.. I agree that it is required for a plain java-code.. but certainly it is tackled differently in spring-cloud i guess – Arun Mar 15 '21 at 16:24

0 Answers0