spring-cloud / spring-cloud-function

Apache License 2.0
1.04k stars 615 forks source link

Error using GCP with a springbootApplication extended custom tag in my application main class #1076

Open alvuberui opened 12 months ago

alvuberui commented 12 months ago

Describe the bug I am making a serverless application with gcp-adapter. In the main class of my application instead of using @SpringBootApplication I am using a custom tag that extends @SpringBootApplication (below you can see the code). The problem is that with my tag the application launches but when testing my function it returns error 500, with exactly the same code but using the @SpringBootApplication tag it does work correctly.

Sample I give you the code of my main class: ` @CustomTagExample public class Application {

/**
 * The main method to start the Spring Boot application.
 *
 * @param args
 *            the arguments
 */
public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
}

} `

And the code of @CustomTagExample is the following: ` @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @SpringBootApplication public @interface CustomTagExample {

} `

Error Here I show you the error:

com.google.cloud.functions.invoker : Failed to execute org.springframework.cloud.function.adapter.gcp.GcfJarLauncher java.lang.IllegalArgumentException: Failed to lookup function to route based on the value of 'spring.cloud.function.definition' property 'com.example.demo.function.CheckDate' at org.springframework.util.Assert.notNull(Assert.java:204) at org.springframework.cloud.function.context.config.RoutingFunction.functionFromDefinition(RoutingFunction.java:207) at org.springframework.cloud.function.context.config.RoutingFunction.route(RoutingFunction.java:152) at org.springframework.cloud.function.context.config.RoutingFunction.apply(RoutingFunction.java:107) at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.doApply(SimpleFunctionRegistry.java:725) at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.apply(SimpleFunctionRegistry.java:577) at org.springframework.cloud.function.observability.ObservationFunctionAroundWrapper.lambda$nonReactorStream$0(ObservationFunctionAroundWrapper.java:50) at io.micrometer.observation.Observation.lambda$observe$4(Observation.java:544) at io.micrometer.observation.Observation.observeWithContext(Observation.java:603) at io.micrometer.observation.Observation.observe(Observation.java:544) at org.springframework.cloud.function.observability.ObservationFunctionAroundWrapper.nonReactorStream(ObservationFunctionAroundWrapper.java:50) at org.springframework.cloud.function.observability.ObservationFunctionAroundWrapper.doApply(ObservationFunctionAroundWrapper.java:45) at org.springframework.cloud.function.context.catalog.FunctionAroundWrapper.apply(FunctionAroundWrapper.java:47) at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.apply(SimpleFunctionRegistry.java:574) at org.springframework.cloud.function.adapter.gcp.FunctionInvoker.service(FunctionInvoker.java:120) at org.springframework.cloud.function.adapter.gcp.GcfJarLauncher.service(GcfJarLauncher.java:53) at com.google.cloud.functions.invoker.HttpFunctionExecutor.service(HttpFunctionExecutor.java:67) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:755) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:547) at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1297) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:485) at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1212) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) at com.google.cloud.functions.invoker.runner.Invoker$NotFoundHandler.handle(Invoker.java:392) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) at org.eclipse.jetty.server.Server.handle(Server.java:500) at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383) at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:547) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375) at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:270) at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103) at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806) at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938) at java.base/java.lang.Thread.run(Thread.java:833)

olegz commented 11 months ago

I was not above to reproduce the error given your explanation. Please provide a working sample (i.e., small project that reproduces the issue, push it to github so we can tale a look)

alvuberui commented 10 months ago

For privacy reasons of the code, I cannot upload an example to a public repository. I will try to explain it in more detail in case it is of any further assistance.

In my case, I do not directly use Spring Boot; instead, I use a library created by me that extends Spring Boot. This means that in my main class, I do not use the @SpringBootApplication annotation, but rather I use @MyLibraryApplication. Not including the @SpringBootApplication annotation causes the error I mentioned.

However, the @MyLibraryApplication annotation does not include anything more than what the @SpringBootApplication includes. I do not understand why the error occurs for that reason.

Example of a normal main class of a spring boot project: ` @SpringBootApplication public class Application {

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

}`

Example of my main class with my own library: ` @MyLibraryApplication public class Application {

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

}`

Code of my library annotation: ` @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @SpringBootApplication public @interface MyLibraryApplication{

}`

As you can see, even when using my library, it is still a Spring Boot application without adding anything additional. However, just because of the absence of the @SpringBootApplication annotation, it no longer works.