Class GrpcExposedMethodValidator

java.lang.Object
io.micronaut.protobuf.json.GrpcExposedMethodValidator
All Implemented Interfaces:
io.micronaut.context.event.BeanInitializedEventListener<Object>, EventListener

@Internal @Singleton public class GrpcExposedMethodValidator extends Object implements io.micronaut.context.event.BeanInitializedEventListener<Object>
Validates beans that implement gRPC services and have methods annotated with @GrpcRestJsonExposed. This validator ensures the annotated methods belong to classes that implement BindableService, which is a requirement for defining a valid gRPC service.
The purpose of this class is to identify and validate any misconfigured or improperly annotated gRPC service classes during the initialization phase of the application's lifecycle. This includes: - Checking if any methods in the bean are annotated with @GrpcRestJsonExposed. - Validating that the containing class of those methods implements the BindableService interface.
If a violation is found during validation, an IllegalStateException is thrown to prevent misconfigured services from running in the application.
This class is triggered automatically as a listener for bean initialization events, utilizing the Micronaut BeanInitializedEventListener.
Note: - This validator explicitly processes beans flagged with the @GrpcRestJsonExposed annotation at the method level. Only those beans are inspected for compliance. - Validation happens prior to PostConstruct or other lifecycle hooks being executed.
Responsibilities: - Enforces that methods annotated with @GrpcRestJsonExposed are correctly defined within a gRPC BindableService. - Logs successful validation or throws an exception if validation fails.
Dependency Injection: This class is a Singleton and is managed by Micronaut's dependency injection.
  • Constructor Details

    • GrpcExposedMethodValidator

      public GrpcExposedMethodValidator()
  • Method Details

    • onInitialized

      public Object onInitialized(io.micronaut.context.event.BeanInitializingEvent<Object> event)

      Fired when a bean is instantiated but the PostConstruct initialization hooks have not yet been called and in this case of bean Provider instances the Provider.get() method has not yet been invoked.

      Specified by:
      onInitialized in interface io.micronaut.context.event.BeanInitializedEventListener<Object>
      Parameters:
      event - The bean initializing event
      Returns:
      The bean or a replacement bean of the same type