Interface CDIExtensionMetadata


public interface CDIExtensionMetadata
This is a interface for CDI Runtime extensions. Liberty features that wish to extend CDI will need to register a service under this interface.

To use this class you must implement at least one of the three methods. If you implement getBeanClasses() all classes returned by that method will be registered with CDI and may be used normally by application code. If you implement getBeanDefiningAnnotationClasses() all annotations returned by that method will become bean defining annotations as per the CDI specifications. If you implement getExtensions() then all classes returned by that method will be treated as CDI extensions any observer methods for container lifecycle events will be called when creating the CDI container for each application. All three methods can be implemented in the same class.

Classes returned from getExtensions() must implement Extension. They do not and should not be listed in a META-INF/services file. It is best practice to not put CDIExtensionMetaData and jakarta.enterprise.inject.spi.Extension on the same class as that would result in CDI and OSGI independently instantiating the class. Even though it is unlikely for the two instances to conflict, it is best to keep the OSGI service and CDI extension separate.

The class that implements this interface should be registered as an OSGi service, for example by annotating it with @Component(service = CDIExtensionMetadata.class, configurationPolicy=IGNORE).

Here is a worked example of a complete CDIExtensionMetadata implementation.

 @Component(service = CDIExtensionMetaData.class, configurationPolicy = IGNORE)
 public class SPIMetaData implements CDIExtensionMetaData {

     @Override
     public Set<Class<?>> getBeanClasses() {
         Set<Class<?>> beans = new HashSet<Class<?>>();
         //This will register a producer class and expose it's produced beans to applications
         beans.add(ClassSPIRegisteredProducer.class);
     }
 }
 
  • Method Summary

    Modifier and Type
    Method
    Description
    default Set<Class<?>>
    All classes returned by this method will be will be found by CDI during type discovery so that they can then be used as beans (or interceptors etc.
    default Set<Class<? extends Annotation>>
    All classes returned by this method will be will be treated as bean defining annotations when CDI performs annotation scanning during application startup.
    default Set<Class<? extends jakarta.enterprise.inject.spi.Extension>>
    All classes returned by this method will be treated as CDI extensions.
  • Method Details

    • getBeanClasses

      default Set<Class<?>> getBeanClasses()
      All classes returned by this method will be will be found by CDI during type discovery so that they can then be used as beans (or interceptors etc. if annotated as such) by the application. All classes must be in the same archive as your CDIExtensionMetadata.
    • getBeanDefiningAnnotationClasses

      default Set<Class<? extends Annotation>> getBeanDefiningAnnotationClasses()
      All classes returned by this method will be will be treated as bean defining annotations when CDI performs annotation scanning during application startup. All classes must be in the same archive as your CDIExtensionMetadata.
    • getExtensions

      default Set<Class<? extends jakarta.enterprise.inject.spi.Extension>> getExtensions()
      All classes returned by this method will be treated as CDI extensions. Override this method if you need to observe CDI container lifecycle events to do something more advanced that just providing additional bean classes. All extensions must be in the same archive as your CDIExtensionMetadata.