Class GrpcClientBeanPostProcessor

java.lang.Object
net.devh.boot.grpc.client.inject.GrpcClientBeanPostProcessor
All Implemented Interfaces:
BeanPostProcessor

public class GrpcClientBeanPostProcessor extends Object implements BeanPostProcessor
This BeanPostProcessor searches for fields and methods in beans that are annotated with GrpcClient and sets them.
  • Constructor Details

    • GrpcClientBeanPostProcessor

      public GrpcClientBeanPostProcessor(ApplicationContext applicationContext)
      Creates a new GrpcClientBeanPostProcessor with the given ApplicationContext.
      Parameters:
      applicationContext - The application context that will be used to get lazy access to the GrpcChannelFactory and StubTransformers.
  • Method Details

    • init

      @PostConstruct public void init()
    • postProcessBeforeInitialization

      public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException
      Specified by:
      postProcessBeforeInitialization in interface BeanPostProcessor
      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 the ClientInterceptors 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.