Skip to content
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

Error creating bean with name 'grpcHealthService' #994

Open
michaldCX opened this issue Nov 20, 2023 · 5 comments
Open

Error creating bean with name 'grpcHealthService' #994

michaldCX opened this issue Nov 20, 2023 · 5 comments
Labels
question A question about this library or its usage

Comments

@michaldCX
Copy link

michaldCX commented Nov 20, 2023

The context

Error creating bean with name 'grpcHealthService'

The question

I'm using
grpc-server-spring-boot-starter - 2.14.0.RELEASE ans when start my app i got error while Initialization bean grpcHealthService

Stacktraces and logs

2023-11-20T18:24:03.159Z [main] error SpringApplication.java:830 - Application run failed 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grpcHealthService' defined in class path resource [net/devh/boot/grpc/server/autoconfigure/GrpcHealthServiceAutoConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class io.grpc.protobuf.services.HealthServiceImpl: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class io.grpc.protobuf.services.HealthServiceImpl
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:628)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301)
	at com.checkmarx.ast.flow.listener.FlowListenerApp.main(FlowListenerApp.java:16)
Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class io.grpc.protobuf.services.HealthServiceImpl: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class io.grpc.protobuf.services.HealthServiceImpl
	at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:209)
	at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110)
	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:478)
	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:342)
	at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:291)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:455)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1808)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620)
	... 15 more
Caused by: java.lang.IllegalArgumentException: Cannot subclass final class io.grpc.protobuf.services.HealthServiceImpl
	at org.springframework.cglib.proxy.Enhancer.generateClass(Enhancer.java:660)
	at org.springframework.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
	at org.springframework.cglib.core.ClassLoaderAwareGeneratorStrategy.generate(ClassLoaderAwareGeneratorStrategy.java:57)
	at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:358)
	at org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:585)
	at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:110)
	at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:108)
	at org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61)
	at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34)
	at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:134)
	at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:319)
	at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:572)
	at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:419)
	at org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:57)
	at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:206)
	... 22 more

The application's environment

Which versions do you use?

  • Spring (boot): 2.6.6
  • grpc-java: 1.51.0
  • grpc-spring-boot-starter: 2.14.0.RELEASE
  • java: version + architecture (64bit?) 11
  • Other relevant libraries...

Additional information

  • Did it ever work before? with grpc-spring-boot-starter 2.11 and grpc-java 1.35 it work fine
  • How can we reproduce it?
  • Do you have a demo?
@michaldCX michaldCX added the question A question about this library or its usage label Nov 20, 2023
@michaldCX
Copy link
Author

michaldCX commented Nov 20, 2023

I do have an interceptor that using @aspect with this method:
@before("execution(public void io.grpc.BindableService+.*(..))")
public void beforeEachIncomingGrpcCall() {
context.restoreForIncomingGrpcCall();
}

And If I remove it the application start as well

@ST-DDT
Copy link
Collaborator

ST-DDT commented Nov 20, 2023

You can also exclude the auto configuration that adds the HealthServiceImpl.

@ConditionalOnProperty(prefix = "grpc.server", name = "health-service-enabled", matchIfMissing = true)

Note: I also had issues with overwriting Bindable.bind/making it non final as that bypassed spring security.

What does your

context.restoreForIncomingGrpcCall();

do?

@michaldCX
Copy link
Author

I dont want to exclude the auto configuration since i do want the functionality of HealthServiceImpl.

context.restoreForIncomingGrpcCall(); Copied values from gRPC context into our contaext (We cannot populate our context directly in IncomingInterceptor, because interceptor and business logic may execute in different threads under high load)

@ST-DDT
Copy link
Collaborator

ST-DDT commented Nov 21, 2023

I dont know much about aspect entrypoint syntax. Maybe you can define an exclude somehow.
Please be careful when using thread locals in combination with streaming calls like this.

Grpc has a class called Context that can be used to store variables throughout the entire call. This library uses it to implememt the grpc request scope feature.
Have you considered scoping your context bean instead?
That way you can already use them in the interceptor.

https://grpc-ecosystem.github.io/grpc-spring/en/server/contextual-data.html

@ST-DDT
Copy link
Collaborator

ST-DDT commented Nov 25, 2023

Is there anything else we can help you with?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A question about this library or its usage
Projects
None yet
Development

No branches or pull requests

2 participants