grpc-ecosystem / grpc-ecosystem/grpc-spring
GrpcGlobalServerInterceptor override in case of another bean of some type.
- Dominant language
- Java
- Stars
- 3.7k
- Forks
- 858
- PR merge metrics
- No merged PRs in 30d
Description
Wanted to override a base interceptor with another one, had tried adding ConditionalOnMissingBean but its not working and both the interceptors are registered.
```
@GrpcGlobalServerInterceptor
@Order(1100)
**@ConditionalOnMissingBean**(GrpcResponseServerInterceptor.class)
class BaseInterceptor extends ServerInterceptor # This is common interceptor (Usually in other modules this is fine)
@GrpcGlobalServerInterceptor
@Order(1100)
class CustomServiceInterceptor extends BaseInterceptor implements GrpcResponseServerInterceptor
```
Also tried Bean aware approach but got error while adding to HashBiMap (value already present)
```
beanFactoryAwareOrderComparator(final ApplicationContext context,
final Class beanType) {
final Map beans = HashBiMap.create(context.getBeansOfType(beanType)).inverse();
```
```
@GrpcGlobalServerInterceptor
@Order(999)
ServerInterceptor serverInterceptor() {
if (null != applicationContext.getBean(GrpcResponseServerInterceptor.class)) {
return applicationContext.getBean(GrpcResponseServerInterceptor.class);
}
return new BaseInterceptor();
}
```
Contributor guide
Research direction
Start by tracing registration through @GrpcGlobalServerInterceptor and @ConditionalOnMissingBean, then inspect beanFactoryAwareOrderComparator and the HashBiMap construction shown in the report. Reproduce the case with BaseInterceptor and CustomServiceInterceptor; done means a custom GrpcResponseServerInterceptor replaces or prevents the base interceptor without duplicate registration or a value-already-present error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- grpc, java, spring-boot
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100