Interface ComponentSource

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface ComponentSource
A functional interface used for contributing Components to an application.

This interface can be registered as a bean within a Spring Boot application in order to contribute components to the application. This interface can be registered as a lambda expression within the configuration class, for example:

 @Configuration
 public class MyMetadataConfiguration {

     @Bean
     public ComponentSource myComponents() {
         return registry -> registry
                 .add("items:list", getItemsList());
     }

     private View<?> getItemsList() {
         // return items list view
     }
 }
 

Alternatively, if lambda expressions are not ideal, this interface can be implemented as a concrete class and then registered as a bean, for example:

 @Configuration
 public class MyMetadataConfiguration {

     @Bean
     public ComponentSource myComponents() {
         return new MyComponentSource();
     }

     public static class MyComponentSource extends ComponentSource {
         @Override
         public void register(ComponentRegistry<?> registry) {
             register.add("items:list", getItemsList());
         }

         private View<?> getItemsList() {
             // return items list view
         }
     }
 }
 
Author:
Nick Crum (ncrum)
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Used for registering or modifying components within the ComponentRegistry.
  • Method Details

    • register

      void register(ComponentRegistry<?> registry)
      Used for registering or modifying components within the ComponentRegistry.
      Parameters:
      registry - the component registry