java.lang.ClassNotFoundException: io.grpc.services.HealthStatusManager
See original GitHub issueThe context
Create a gRPC server using grpc-spring-boot-starter library.
The bug
Even when grpc.server.healthServiceEnabled=false, GrpcServerAutoConfiguration tries to create a HealthStatusManager, which fails with a ClassNotFoundException if io.grpc:grpc-services is not on the classpath. Now, if the application has indicated that it doesn’t want to enable health service, there’s no reason for it to add an unnecessary jar on the classpath that is “secretly” needed by the grpc-spring-boot-starter library.
My suggestion is to check for the presence of the class, as well as the property grpc.server.healthServiceEnabled, before creating the HealthStatusManager.
Stacktrace and logs
java.lang.IllegalStateException: Error processing condition on net.devh.boot.grpc.server.autoconfigure.GrpcServerAutoConfiguration.defaultGrpcServerProperties
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:60)
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108)
...
Caused by: java.lang.IllegalStateException: Failed to introspect Class [net.devh.boot.grpc.server.autoconfigure.GrpcServerAutoConfiguration] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@9e89d68]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481)
...
Caused by: java.lang.NoClassDefFoundError: io/grpc/services/HealthStatusManager
at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
...
Caused by: java.lang.ClassNotFoundException: io.grpc.services.HealthStatusManager
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
...
Steps to Reproduce
N/A
The application’s environment
Which versions do you use?
- Spring (boot): 2.3.1.RELEASE
- grpc-java: 1.30.2
- grpc-spring-boot-starter: 2.9.0.RELEASE
Additional context
- Did it ever work before? No
- Do you have a demo? No
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Related StackOverflow Question
Same applies for reflection service. There’s a good reason they are in a separate dependency jar, separation of concerns.
I will refactor the related code and remove the health manager from it. I just ran into it during my tests…