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 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