Package net.devh.boot.grpc.client.inject
Class GrpcClientBeanPostProcessor
java.lang.Object
net.devh.boot.grpc.client.inject.GrpcClientBeanPostProcessor
- All Implemented Interfaces:
BeanPostProcessor
This
BeanPostProcessor
searches for fields and methods in beans that are annotated with GrpcClient
and sets them.-
Constructor Summary
ConstructorsConstructorDescriptionGrpcClientBeanPostProcessor
(ApplicationContext applicationContext) Creates a new GrpcClientBeanPostProcessor with the given ApplicationContext. -
Method Summary
Modifier and TypeMethodDescriptionvoid
init()
protected List<ClientInterceptor>
interceptorsFromAnnotation
(GrpcClient annotation) Gets or creates theClientInterceptor
s that are referenced in the given annotation.postProcessBeforeInitialization
(Object bean, String beanName) protected <T> T
processInjectionPoint
(Member injectionTarget, Class<T> injectionType, GrpcClient annotation) Processes the given injection point and computes the appropriate value for the injection.protected <T> T
valueForMember
(String name, Member injectionTarget, Class<T> injectionType, Channel channel) Creates the instance to be injected for the given member.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.beans.factory.config.BeanPostProcessor
postProcessAfterInitialization
-
Constructor Details
-
GrpcClientBeanPostProcessor
Creates a new GrpcClientBeanPostProcessor with the given ApplicationContext.- Parameters:
applicationContext
- The application context that will be used to get lazy access to theGrpcChannelFactory
andStubTransformer
s.
-
-
Method Details
-
init
@PostConstruct public void init() -
postProcessBeforeInitialization
- Specified by:
postProcessBeforeInitialization
in interfaceBeanPostProcessor
- Throws:
BeansException
-
processInjectionPoint
protected <T> T processInjectionPoint(Member injectionTarget, Class<T> injectionType, GrpcClient annotation) Processes the given injection point and computes the appropriate value for the injection.- Type Parameters:
T
- The type of the value to be injected.- Parameters:
injectionTarget
- The target of the injection.injectionType
- The class that will be used to compute injection.annotation
- The annotation on the target with the metadata for the injection.- Returns:
- The value to be injected for the given injection point.
-
interceptorsFromAnnotation
protected List<ClientInterceptor> interceptorsFromAnnotation(GrpcClient annotation) throws BeansException Gets or creates theClientInterceptor
s that are referenced in the given annotation.Note: This methods return value does not contain the global client interceptors because they are handled by the
GrpcChannelFactory
.- Parameters:
annotation
- The annotation to get the interceptors for.- Returns:
- A list containing the interceptors for the given annotation.
- Throws:
BeansException
- If the referenced interceptors weren't found or could not be created.
-
valueForMember
protected <T> T valueForMember(String name, Member injectionTarget, Class<T> injectionType, Channel channel) throws BeansException Creates the instance to be injected for the given member.- Type Parameters:
T
- The type of the instance to be injected.- Parameters:
name
- The name that was used to create the channel.injectionTarget
- The target member for the injection.injectionType
- The class that should injected.channel
- The channel that should be used to create the instance.- Returns:
- The value that matches the type of the given field.
- Throws:
BeansException
- If the value of the field could not be created or the type of the field is unsupported.
-