-
Notifications
You must be signed in to change notification settings - Fork 618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
4.1.3 GCP Adapter - GcfJarLauncher: Failed to lookup function #1164
Comments
On invocation, the beans of our application aren't scanned. However, locally with the function plugin, we saw all beans. <logger name="org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLogger" level="DEBUG" additivity="false">
<appender-ref ref="consoleAppender"/>
</logger>
<logger name="org.springframework.context.annotation.ClassPathBeanDefinitionScanner" level="DEBUG" additivity="false">
<appender-ref ref="consoleAppender"/>
</logger>
<logger name="org.springframework.beans.factory.support.DefaultListableBeanFactory" level="DEBUG" additivity="false">
<appender-ref ref="consoleAppender"/>
</logger> |
I have the same problem, it looks like beans are not being created unless they are defined in main class (@SpringBootApplication). I ended up defining all beans like this:
It works if you define a bean as functional interface or as a separate class, as I have it:
|
@ihoroshko-n-ix I confirm, this solution works fine. So the original problem becomes from the scanning step treat by the Spring IoC to find the stereotyps. We loose on simplicity to create beans but we gain on cold start 😅 Once again, thanks for your solution |
@ihoroshko-n-ix & @gfourny-sfeir |
After hours of working on this issue, I found that the issue is with Spring boot newer version which does not have support yet and hence downgrade your Spring boot version to 3.1.x in my case tested with 3.1.10 version and it works fine. Look at my example in https://github.com/balaji1974/functions And I solved this issue by following this thread on the same issue: |
@ihoroshko-n-ix @gfourny-sfeir Can you post the code in Github repo as I am not sure of how to inject the service into the Function interface |
@rajakumare1 I couldn't share our repos because they're private. @SpringBootApplication
public class VodProfilAvatarApplication {
public static void main(String[] args) {
SpringApplication.run(VodProfilAvatarApplication.class, args);
}
@Bean
RestClient restClient(RestClient.Builder builder, VodProfilAvatarProperties properties) {
return builder.baseUrl(properties.avatarGeneratorBaseUrl()).build();
}
//Business service without @Service or @Component annotation
@Bean
AvatarWriter avatarWriter(Storage storage, VodProfilAvatarProperties properties) {
return new AvatarWriter(storage, properties);
}
//Business service without @Service or @Component annotation
@Bean
AvatarClient avatarClient(RestClient restClient) {
return new AvatarClient(restClient);
}
//Business service without @Service or @Component annotation
@Bean
AvatarGenerator avatarGenerator(AvatarClient avatarClient, AvatarWriter avatarWriter) {
return new AvatarGenerator(avatarClient, avatarWriter);
}
/**
* {@link Supplier} called by Cloud Function and refers in application.yaml
*
* @return {@link Supplier<String>}
*/
@Bean
Supplier<AvatarResponse> generateAvatar(AvatarGenerator avatarGenerator) {
return avatarGenerator::generate;
}
} In your application.yaml: spring:
application:
name: vod-profil-avatar
cloud:
function:
definition: generateAvatar #Name of the bean |
@olegz We suspect the bug comes from the FunctionInvoker class in the adapter code by these lines: Thread.currentThread() // TODO: remove after upgrading to 1.0.0-alpha-2-rc5
.setContextClassLoader(FunctionInvoker.class.getClassLoader()); ❓ WhyBecause the classLoader used to scan is provides these lines and cannot scan the package created by our applications |
Happy to report that both the issue mentioned in #1085 and this one are resolved for me after upgrading to version 4.1.4 (tested with Spring Cloud Release Train 2023.0.4 and Spring Boot 3.3.6). My Spring Boot cloud function app starts correctly again when deployed to GCP, and all beans are correctly scanned 👍. |
Describe the bug
We have still bug on spring-cloud-function-adapter-gcp 4.1.3.
We using Spring Boot 3.3.1 with Spring Cloud Function. When the function is invoking, we have this error:
It was working with Spring Boot 3.1.x
Sample
pom.xml:
The java Bean :
The properties:
I have two integration tests to validate the function, all passed:
The text was updated successfully, but these errors were encountered: